【问题标题】:How to improve app performance when clicking hamburger menu items in UWP?在 UWP 中单击汉堡菜单项时如何提高应用程序性能?
【发布时间】:2021-08-11 14:14:36
【问题描述】:

我在我的 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));
    }

【问题讨论】:

    标签: c# windows uwp uwp-xaml uwp-navigation


    【解决方案1】:

    通常从一个页面导航到另一个页面需要 2 到 3 秒。

    你不应该在页面的构造器中处理同步调用,它会阻塞ui线程,使导航消耗更多时间。

    目前,UWP 包含原生的NavigationView,用于管理导航,更多请参考this

    您还可以使用模板工作室制作模板应用程序,这样可以节省更多时间来配置应用程序的基础架构。更多详情请参考here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-25
      • 1970-01-01
      • 2018-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-29
      相关资源
      最近更新 更多