c# – 在Windows 10 UWP开发中是否有Windows 8.1 SettingsFlyout的替代方案?

我目前正在开发 Windows 10 UWP应用程序.在我升级到Windows 10之前,我在Windows 8.1中使用了SettingsFlyout类.现在我在stackoverflow上重新启动,Windows 10不支持此类.

那么Windows 10 UWP中的弹出窗口是否有一个很好的替代方案,它具有相同或类似的处理方式?

解决方法

如果您想要替换设置弹出窗口,那么有一些可能的方法
1.使用AppBar中的设置和导航添加SettingsPage.xaml页面

<Page.TopAppBar>
    <CommandBar IsOpen="False" CloseddisplayMode="Minimal">
        <CommandBar.PrimaryCommands>
<AppBarButton x:Name="btnSettings" Label="Settings" Click="btnSettings_Click" Icon="Setting"  >
            </AppBarButton>
        </CommandBar.PrimaryCommands>
    </CommandBar>
</Page.TopAppBar>

并实现点击事件:

private void btnSettings_Click(object sender,RoutedEventArgs e)
    {
        this.Frame.Navigate(typeof(SettingsPage));
    }

在这种情况下,最好添加Back按钮.
在OnLaunched事件结束时添加

rootFrame.Navigated += OnNavigated;
SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;

添加

private void OnNavigated(object sender,NavigationEventArgs e)
    {
 SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
        ((Frame)sender).CanGoBack ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed;
    }

    private void OnBackRequested(object sender,BackRequestedEventArgs e)
    {
        Frame rootFrame = Window.Current.Content as Frame;

        if (rootFrame.CanGoBack)
        {
            e.Handled = true;
            rootFrame.GoBack();
        }
    }

2.同时添加带设置的xaml页面,但使用SplitView控件导航并创建汉堡菜单

Windows 10 SplitView – Build Your First Hamburger Menu
Implementing a Simple Hamburger Navigation Menu

3.将设置移至ContentDialog

4.如果没有太多设置,可以将它们置于Flyout控件中

<Button Content="Settings">
<Button.Flyout>
<MenuFlyout>
<ToggleMenuFlyoutItem Text="Toggle Setting" />
<MenuFlyoutSeparator />
<MenuFlyoutItem Text="Setting 1" />
<MenuFlyoutItem Text="Setting 2" />
<MenuFlyoutItem Text="Setting 3" />
</MenuFlyout>
</Button.Flyout>
</Button>

相关文章

目录简介使用JS互操作使用ClipLazor库创建项目使用方法简单测...
目录简介快速入门安装 NuGet 包实体类User数据库类DbFactory...
本文实现一个简单的配置类,原理比较简单,适用于一些小型项...
C#中Description特性主要用于枚举和属性,方法比较简单,记录...
[TOC] # 原理简介 本文参考[C#/WPF/WinForm/程序实现软件开机...
目录简介获取 HTML 文档解析 HTML 文档测试补充:使用 CSS 选...