简体   繁体   中英

How to improve app performance when clicking hamburger menu items in UWP?

I'm using Template 10 for the MVVM and the Hamburger menu in my UWP application. Normally from page to page navigation takes 2 to 3 secs. When App is in the background for more than 5 hours, then come back to the foreground, and page navigation takes 8 sec. How can I reduce the delay from page to page navigation?

XAML code for Menu Item:

```<Controls:HamburgerButtonInfo ClearHistory="True" x:Name="manifest" Selected="manifest_Selected" Unselected="manifest_Unselected" PageType="views:Manifest">
                <StackPanel Orientation="Horizontal">
                    <BitmapIcon Width="30" Height="30" x:Name="manifesticon" Margin="10,20,0,0" UriSource="ms-appx:///Assets/ic_menu_manifest.png"/>
                    <TextBlock Margin="16,20,0,0" x:Name="manifesttext"
                           VerticalAlignment="Center"
                           Text="Manifest" />
                </StackPanel>
   </Controls:HamburgerButtonInfo>```

CS code:

public void manifest_Selected(object sender, RoutedEventArgs e)
    {
        reportElement = new HamburgerButtonInfo();
        manifesticon.Foreground = (Brush)Application.Current.Resources["HeaderBackground"];
        manifesttext.Foreground = (Brush)Application.Current.Resources["HeaderBackground"];
        reportElement = manifest;
        if (report.IsEnabled)
        {
            report_Unselected(sender, e);
        }
    }

    public void manifest_Unselected(object sender, RoutedEventArgs e)
    {
        manifesticon.Foreground = new SolidColorBrush(Color.FromArgb(255, 229, 229, 229));
        manifesttext.Foreground = new SolidColorBrush(Color.FromArgb(255, 229, 229, 229));
    }

Normally from page to page navigation takes 2 to 3 secs.

You should not process synchronous call in page's constructer, it will block the ui thread to make navigation consume more time.

Currently, UWP contain native NavigationView that used to manage navigation, For more please refer this .

And you could also make template app with template studio that could save more time to configure your app's base architecture. Fore more detail please refer here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM