首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Splitview内容属性窗口通用

Splitview内容属性窗口通用
EN

Stack Overflow用户
提问于 2015-08-08 11:40:09
回答 1查看 2K关注 0票数 0

我在我的应用程序中包括了splitview。但是我不知道如何填充我的splitview的内容。我读到我应该把框架放在里面。所以我有了我的Mainpage.xaml,如果用户单击一个menue按钮,splitview的内容应该是helpandabout.xaml。或者,我应该在content属性中嵌套什么?以及如何用不同的页面替换内容。,我目前只是试图改变网格的可见性,如果用户按下一个按钮,但这不是这个控制背后的哲学。如下所示:

代码语言:javascript
复制
<Grid x:Name="Grid1" Visibility="Visible"> </Grid>
<Grid Visibility="Collapsed" x:Name="Grid2"> </Grid>

用户在splitview窗格中按下一个按钮,然后代码执行以下操作:

代码语言:javascript
复制
Grid1.Visibility = Visibility.Collapsed;
Grid2.Visibility = Visibility.Visible;

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-08 21:01:15

实际上,您可以用SplitView替换完整的应用程序标准,并创建导航等。

我所做的是:

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

2.- -在学习了它的工作原理之后,它有一些技巧,比如命令栏在appbar之外,等等,您可以提取库中的所有代码。

AppShell.xaml,NavMenuItem,NavMenuListView.cs,PageHeader.xaml

3.-创建以下扩展:

代码语言:javascript
复制
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添加中引用所有这些

代码语言:javascript
复制
protected override void OnLaunched(LaunchActivatedEventArgs e)
    {
        NavigationExtensions.Initialize<PersonalView>(Navigation.GetNavigationMenuItems(),OnNavigationFailed,e);
    }

例如,在该方法中:

代码语言:javascript
复制
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;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31892725

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档