简体   繁体   English

如何将CommandBar添加到NavigationView标头中?

[英]How to add CommandBar to NavigationView Header?

I need to add a CommandBar to my NavigationView header to replace the plain text - however I don't know how to drill into the template and add one. 我需要在我的NavigationView标头中添加一个CommandBar来替换纯文本-但是我不知道如何深入到模板中并添加一个。

Right now, I just have the NavigationView in a Grid, with the header set to simple text such as Welcome... 现在,我只是将NavigationView放在一个网格中,标题设置为简单文本,例如Welcome...。

<Grid Background="{ThemeResource SystemControlAltHighAcrylicWindowBrush}">
    <NavigationView x:Name="NavigationView" Header="Welcome" SelectionChanged="{x:Bind mainViewModel.selectionChanged, Mode=OneWay}" Background="{ThemeResource SystemControlAltHighAcrylicWindowBrush}">

Currently, I have the commandbar below the header in a grid as follows: 当前,命令栏位于网格标题下方,如下所示:

<Grid Background="{ThemeResource SystemControlAltHighAcrylicWindowBrush}" VerticalAlignment="Top">
            <CommandBar Background="{ThemeResource SystemControlAltHighAcrylicWindowBrush}"
                Visibility="{Binding listsClicked, Converter={StaticResource boolToVisibilityConverter}}"
                        Height="30">
                <AppBarButton Icon="Back" Label="Back"/>
            </CommandBar>
            <CommandBar Background="{ThemeResource SystemControlAltHighAcrylicWindowBrush}"
                Visibility="{Binding addinCalculatorClicked, Converter={StaticResource boolToVisibilityConverter}}"
                        Height="40">
                <AppBarButton Icon="Forward" Label="Forward"/>
            </CommandBar>

Notice that the CommandBar's visibility uses binding and a converter. 请注意,CommandBar的可见性使用绑定和转换器。 If I'll need to edit the template of the CommandBar in order to do so when adding it into the template of the NavigationView, I'll need to know how to do that as well - which should be simple. 如果在将CommandBar的模板添加到NavigationView的模板中时需要进行编辑,则我也需要知道如何执行该操作-这应该很简单。

I don't know how to drill into the template and add one. 我不知道如何钻入模板并添加一个。

You just need to put it in the NavigationView's HeaderTemplate like the following: 您只需要像下面这样将其放在NavigationView的HeaderTemplate中:

<Page.Resources>
    <local:boolToVisibilityConverter x:Key="boolToVisibilityConverter"> 
    </local:boolToVisibilityConverter>
</Page.Resources>
<NavigationView>
        <NavigationView.HeaderTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <CommandBar Background="{ThemeResource SystemControlAltHighAcrylicWindowBrush}"
            Visibility="{Binding listsClicked, Converter={StaticResource boolToVisibilityConverter}}"
                    Height="30">
                        <AppBarButton Icon="Back" Label="Back"/>
                    </CommandBar>
                    <CommandBar Background="{ThemeResource SystemControlAltHighAcrylicWindowBrush}"
            Visibility="{Binding addinCalculatorClicked, Converter={StaticResource boolToVisibilityConverter}}"
                    Height="40">
                        <AppBarButton Icon="Forward" Label="Forward"/>
                    </CommandBar>
                </StackPanel>
            </DataTemplate>
        </NavigationView.HeaderTemplate>
</NavigationView>

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

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