首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Uno主布局

Uno主布局
EN

Stack Overflow用户
提问于 2021-06-16 12:00:54
回答 2查看 138关注 0票数 1

我是Uno的新手,我一直在跟踪帧导航教程。我注意到,当框架导航时,整个窗口都会发生变化。这是好的,但不是最佳的。在Uno中有没有一种方法可以有一个主布局,就像您在ASP.Net MVC项目中看到的那样?我不愿在每个页面上实现导航菜单。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-06-16 14:49:18

虽然不完全是你想要的,但我相信NavigationView控件是你最近的赌注。您可以禁用CompactView并获得类似于在UnoGallery中显示的内容。

票数 0
EN

Stack Overflow用户

发布于 2021-06-17 18:51:45

要扩展@matfillion的答案,如果NavigationView不适合您的需要,您可以轻松地滚动自己的导航外壳,同时利用内置的框架导航。在您的应用程序中,不需要Frame作为顶级控件。

这里有一个非常简单的例子来说明这个原理。在页面之间导航时,导航列表将保持在顶部可见。

Shell.xaml:

代码语言:javascript
复制
<UserControl x:Class="UnoTestbed44.Shell"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <ListView x:Name="NavigationList"
                  Background="LightGray"
                  ItemsSource="{x:Bind Pages}"
                  Grid.Row="0"
                  DisplayMemberPath="Label"
                  SelectionChanged="NavigationList_SelectionChanged">
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
        </ListView>
        <Frame x:Name="MainFrame"
               Grid.Row="1" />
    </Grid>
</UserControl>

Shell.xaml.cs:

代码语言:javascript
复制
using System;
using System.Linq;
using Windows.UI.Xaml.Controls;

namespace UnoTestbed44
{
    public sealed partial class Shell : UserControl
    {
        public NavigationItem[] Pages { get; } = new[] { 
            new NavigationItem {Label = "First page", PageType = typeof(Page1)},
            new NavigationItem {Label = "Second page", PageType = typeof(Page2)},
        };
        public Shell()
        {
            this.InitializeComponent();
        }

        private void NavigationList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.FirstOrDefault() is NavigationItem navigationItem)
            {
                MainFrame.Navigate(navigationItem.PageType);
            }
        }

        public class NavigationItem
        {
            public string Label { get; set; }
            public Type PageType { get; set; }
        }
    }
}

OnLaunched()中重写App.xaml.cs:

代码语言:javascript
复制
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
#if NET5_0 && WINDOWS
            _window = new Window();
            _window.Activate();
#else
            _window = Windows.UI.Xaml.Window.Current;
#endif

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (_window.Content == null)
            {
                _window.Content = new Shell();
            }

#if !(NET5_0 && WINDOWS)
            if (e.PrelaunchActivated == false)
#endif
            {
                // Ensure the current window is active
                _window.Activate();
            }
        }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68002276

复制
相关文章

相似问题

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