簡體   English   中英

單擊 UWP 中的漢堡菜單項時如何提高應用程序性能?

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

我在我的 UWP 應用程序中為 MVVM 和漢堡菜單使用模板 10。 通常從一頁到另一頁導航需要 2 到 3 秒。 App在后台超過5小時,然后回到前台,頁面導航需要8秒。 如何減少頁面到頁面導航的延遲?

菜單項的 XAML 代碼:

```<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代碼:

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));
    }

通常從一頁到另一頁導航需要 2 到 3 秒。

您不應該在頁面的構造函數中處理同步調用,它會阻塞 ui 線程,使導航消耗更多時間。

目前,UWP 包含用於管理導航的原生NavigationView ,更多信息請參考

您還可以使用模板工作室制作模板應用程序,這樣可以節省更多時間來配置應用程序的基礎架構。 更多細節請參考這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM