我需要将CommandBar添加到我的NavigationView标头中以替换纯文本-但是我不知道如何钻入模板并添加一个。
现在,我只是将NavigationView放在一个网格中,标题设置为简单文本,例如Welcome ...
<Grid Background="{ThemeResource SystemControlAltHighAcrylicWindowBrush}">
<NavigationView x:Name="NavigationView" Header="Welcome" SelectionChanged="{x:Bind mainViewModel.selectionChanged, Mode=OneWay}" Background="{ThemeResource SystemControlAltHighAcrylicWindowBrush}">
目前,我的命令栏位于网格标题下方,如下所示:
<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>
请注意,CommandBar的可见性使用绑定和转换器。如果要在将CommandBar的模板添加到NavigationView的模板中时进行编辑,我也需要知道如何做-这应该很简单。
答案 0 :(得分:0)
我不知道如何钻入模板并添加一个。
您只需要像下面这样将其放在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>