Rudi
Rudi

Reputation: 936

Windows Phone - Avoid high resource usage

I used the Windows Store-Kit to test my Windows Phone 8 App and it failed. It says 'High Resource Usage'. I'm using the MVVM-Pattern, which means I'm binding my Elements in the View with the ViewModel propertys.

Example when high usage: I have a MainView which has a ContentControl. The Content of the ContentControl is another View (let's call it ChildView). When I click on a TextBox in the ChildView, the InputScope pops up (where you can type) and the View goes up, so the TextBox can be seen. When the View goes up (note that the TextBox is in a Pivot), it starts to lagg. I don't know why, since I only focus the TextBox and the PivotItem goes up. My question is how can I lower the resource usage? If you need anything, write it and I'll post it here.

MainPage.xaml

 <Grid>
    <Grid x:Name="LayoutRoot"  HorizontalAlignment="Left">

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <ScrollViewer Name="MyScrollViewer" Height="Auto" HorizontalAlignment="Left" VerticalAlignment="Top" Width="Auto" HorizontalScrollBarVisibility="{Binding Horizontal}" VerticalScrollBarVisibility="{Binding Vertical}">
            <!--ContentPanel - zusätzliche Inhalte hier platzieren-->
            <StackPanel ScrollViewer.HorizontalScrollBarVisibility="Auto" Grid.Row="2" Opacity="50">
                <ContentControl Content="{Binding MyContent}" Name="MyContentControl" IsTabStop="False" VerticalContentAlignment="Stretch"  HorizontalContentAlignment="Stretch"/>
            </StackPanel>

        </ScrollViewer>
    </Grid>
</Grid>

ChildView.xaml http://textuploader.com/?p=6&id=zMDoD

Store-Kit result (in german, but I think it's clear) http://i.imagebanana.com/img/j6z24o9a/Unbenannt.png

this is what a property in the ViewModel of the view looks like (which are shown in the Store-Kit result)

    private string _anlohnsteuer;
    public string ANLohnsteuer
    {
        get { return _anlohnsteuer; }
        set
        {
            _anlohnsteuer = value;
            RaisePropertyChanged(() => ANLohnsteuer);
        }
    }

Upvotes: 0

Views: 327

Answers (2)

Rudi
Rudi

Reputation: 936

Great article by this guy:

http://fiercedesign.wordpress.com/2012/08/14/windows-phone-performance-best-practices/

Read the Topic "Redraw Regions"

If the UI is not smooth/fluid, you have to check which elements are being redrawn every time by the UI. You can do this by going to the App.xaml.cs and enable Redraw Regions Application.Current.Host.Settings.EnableRedrawRegions = true;

If an area or element is flickering, something is wrong. Try to add CacheMode="BitmapCache"

to your element.

I had a lot of color flickering in my app. The UI redrew i.e. my TextBlocks, even though I didn't change it. All I had to do was to change all the elements (especially the TextBlocks and the Grids) like this:

The App is now running fluid.

Edit: I had a MainViewMode which initialized 5 other ViewModels (MainView contains 1 ContentControl and depending on which button the user clicks, the ContentControl gets a new View and the View will get a new ViewModel). Since I load only 1 View and 1 ViewModel on startup, I've put the initialization of the other 4 ViewModels in a BackgroundWorker -> App start time was ~7 sec before, now it's only 2!

Upvotes: 0

SBoss
SBoss

Reputation: 9215

I'm not sure, but it seems you're trying to put a scrollable control into another scrollable control. That would be a bad idea.

Pivots generally use a lot of resources, so I'd avoid using them when you're dealing with more than 4 items (depending on the content).

Viel Glück mit deiner App.

Upvotes: 1

Related Questions