0

我在我的应用程序中包含了拆分视图。但我不知道如何填充我的 splitview 的内容。我读到我应该将框架嵌套在那里。所以我有我的 Mainpage.xaml,如果用户单击一个菜单按钮,则拆分视图的内容应该是例如 helpandabout.xaml。或者我应该在 content 属性中嵌套什么?以及如何用不同的页面替换内容。 我目前只是尝试在用户按下一个按钮时更改网格的可见性,但这不是此控件背后的理念。像这样:

<Grid x:Name="Grid1" Visibility="Visible"> </Grid>
<Grid Visibility="Collapsed" x:Name="Grid2"> </Grid>

然后用户在拆分视图窗格上按下一个按钮,代码执行以下操作:

Grid1.Visibility = Visibility.Collapsed;
Grid2.Visibility = Visibility.Visible;

我知道那是一个愚蠢的代码。

4

1 回答 1

0

实际上,您可以用 SplitView 和 Create Navigation 等替换完整的 App 标准。

我所做的是以下内容:

1- 从这里学习导航示例: uwp 导航示例

2.- 在你了解它是如何工作的之后,它有一些技巧,比如命令栏在应用栏之外,等等。你可以提取库中的所有代码。

AppShell.xaml、NavMenuItem、NavMenuListView.cs、PageHeader.xaml

3.- 创建以下扩展:

public class NavigationExtensions
{

public static void Initialize<T>(List<NavMenuItem> list, NavigationFailedEventHandler OnNavigationFailed, LaunchActivatedEventArgs e)
    {
        AppShell shell = Window.Current.Content as AppShell;

        // Do not repeat app initialization when the Window already has content,
        // just ensure that the window is active
        if (shell == null)
        {
            // Create a AppShell to act as the navigation context and navigate to the first page
            shell = new AppShell();

            shell.NavigationList = list;

            try
            {
                shell.CurrentItem = list.First(i => i.DestPage == typeof(T));
            }
            catch
            {

            }

            // Set the default language
            shell.Language = Windows.Globalization.ApplicationLanguages.Languages[0];

            shell.AppFrame.NavigationFailed += OnNavigationFailed;

            if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                //TODO: Load state from previously suspended application
            }
        }

        // Place our app shell in the current Window
        Window.Current.Content = shell;

        if (shell.AppFrame.Content == null)
        {
            // When the navigation stack isn't restored, navigate to the first page
            // suppressing the initial entrance animation.

            shell.AppFrame.Navigate(typeof(T), e.Arguments, new Windows.UI.Xaml.Media.Animation.SuppressNavigationTransitionInfo());
        }

        // Ensure the current window is active
        Window.Current.Activate();
    }

}

4.- 在您的项目和 App.xaml.cs 添加中引用所有这些

protected override void OnLaunched(LaunchActivatedEventArgs e)
    {
        NavigationExtensions.Initialize<PersonalView>(Navigation.GetNavigationMenuItems(),OnNavigationFailed,e);
    }

例如,方法在哪里:

public class Navigation
{
    public static List<NavMenuItem> GetNavigationMenuItems()
    {
        var list = new List<NavMenuItem>(
        new[]
        {
            new NavMenuItem()
            {
                Symbol = Symbol.Contact,
                Label = "Personal",
                DestPage = typeof(PersonalView)
            },
            new NavMenuItem()
            {
                Symbol = Symbol.World,
                Label = "Countries",
                DestPage = typeof(CountriesView)
            },
            new NavMenuItem()
            {
                Symbol = Symbol.Setting,
                Label = "Settings",
                DestPage = typeof(SettingsView)
            },
        });

        return list;
    }
}
于 2015-08-08T21:01:15.987 回答