简体   繁体   English

UWP NavigationView和TabView碰撞

[英]UWP NavigationView and TabView collision

As you can see from the top of the image, the hamburger button of the NavigationView overlaps with my TabView.TabStartHeader . 从图像顶部可以看出, NavigationView的汉堡包按钮与我的TabView.TabStartHeader重叠。 The TabView is in a Frame of MainPage while NavigationView is in the MainPage . TabView位于MainPageFrame ,而NavigationView位于MainPage

Now I want them aligned horizontally with the hamburger button on the left and the Add button on the right. 现在我想让它们与左边的汉堡包按钮和右边的添加按钮水平对齐。 How can I achieve that? 我怎样才能做到这一点?

在此输入图像描述

XAML of MainPage: https://github.com/SeakyLuo/SMPlayer/blob/master/SMPlayer/MainPage.xaml MainPage的XAML: https//github.com/SeakyLuo/SMPlayer/blob/master/SMPlayer/MainPage.xaml

XAML of TabView: https://github.com/SeakyLuo/SMPlayer/blob/master/SMPlayer/PlaylistsPage.xaml TabView的XAML: https//github.com/SeakyLuo/SMPlayer/blob/master/SMPlayer/PlaylistsPage.xaml

The problem that you are facing is due to the default behavior of the NavigationView . 您面临的问题是由于NavigationView的默认行为。 Whenever the window size is reduced to a certain limit, PaneDisplayMode is changed to LeftMinimal to increase the viewable area . 每当窗口大小减小到某个限制时, PaneDisplayMode就会更改为LeftMinimal以增加可视区域。 Thus the Frame which was previously sitting beside the navigation view is now directly below the navigation bar . 因此,先前位于导航视图旁边的Frame现在位于导航栏的正下方。 Due to this, the "New Tab" button of the Tab View goes below the "hamburger Button" of the navigation bar . 因此, Tab View的“新标签”按钮位于导航栏的“汉堡按钮”下方。

The highlighted selection shows the area covered by the Frame which has the page with the TabView 突出显示的选项显示框架所覆盖的区域,该区域具有带TabView的页面

在此输入图像描述

To prevent this from happening the easiest way would be to specify a single PaneDisplayMode for all screen sizes : 为了防止这种情况发生,最简单的方法是为所有屏幕尺寸指定一个PaneDisplayMode

<NavigationView
            x:Name="MainNavigationView"
            ........
            PaneDisplayMode="LeftCompact">

A better approach would be to switch the PaneDisplayMode using VisualStateManager or Adaptive Triggers . 更好的方法是使用VisualStateManager或Adaptive Triggers切换PaneDisplayMode

For example you can have the PaneDisplayMode as 'Auto' for window size greater than ~700px (based on your preference) and for lower window sizes you can switch it to 'Top'/'Left Compact'. 例如,您可以将PaneDisplayMode为“Auto”,窗口大小大于~700px(根据您的偏好),对于较小的窗口大小,您可以将其切换为“Top”/“Left Compact”。

XAML Code XAML代码

<VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="VisualStateGroup">
            <VisualState x:Name="VisualStateMin0">
                <VisualState.Setters>
                    <Setter Target="MainNavigationView.(NavigationView.PaneDisplayMode)" Value="LeftCompact"/>
                </VisualState.Setters>
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="1" MinWindowHeight="1"/>
                </VisualState.StateTriggers>
            </VisualState>
            <VisualState x:Name="VisualStateMin700">
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="700" MinWindowHeight="1"/>
                </VisualState.StateTriggers>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>

You should see a behavior like this : 你应该看到这样的行为:

PaneDisplayMode - Top for small window size : PaneDisplayMode - 小窗口大小的顶部

在此输入图像描述

PaneDisplayMode - Left Compact for small window size : PaneDisplayMode - 用于小窗口大小的左侧紧凑型

在此输入图像描述


Update after Seaky Luo's comment : Seaky Luo的评论后更新:

Exact solution (though it does not look as natural as the other solutions): 确切的解决方案(虽然它看起来不像其他解决方案那样自然 ):

For this you will need to add left margin to the "New Tab" button when the window size is small and the NavigationView switches to LeftMinimal . 为此,当窗口大小较小且NavigationView切换到LeftMinimal时,您需要在“New Tab”按钮上添加左边距。

I found that when the width is around ~640 the navigation view goes into LeftMinimal (you might have to fine tune that number). 我发现当宽度约为640左右时,导航视图会进入LeftMinimal (您可能需要对该数字进行微调)。

XAML Code : [To be added to the Page called within the frame (PlayListsPage.xaml in this case)] XAML代码: [要添加到框架内调用的页面(在本例中为PlayListsPage.xaml)]

<VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="VisualStateGroup">
            <VisualState x:Name="VisualStateMin0">
                <VisualState.Setters>
                    <Setter Target="NewPlaylistButton.(FrameworkElement.Margin)">
                        <Setter.Value>
                            <Thickness>40,0,0,0</Thickness>
                        </Setter.Value>
                    </Setter>
                </VisualState.Setters>
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="1" MinWindowHeight="1"/>
                </VisualState.StateTriggers>
            </VisualState>
            <VisualState x:Name="VisualStateMin640">
                <VisualState.StateTriggers>
                    <AdaptiveTrigger MinWindowWidth="640" MinWindowHeight="1"/>
                </VisualState.StateTriggers>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>

It should look something like this : 它应该看起来像这样:

在此输入图像描述

Hope this helps ! 希望这可以帮助 !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM