我使用 Windows Template Studio 为 Windows 10 创建了一个项目,并添加了一个主详细信息页面。然后,我将 master 和 details 命令栏添加到 Microsoft.Toolkit.Uwp.UI.Controls.MasterDetailsView,如下所示:
<Page
x:Class="MasterDetails.Views.MasterDetailPage"
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"
Style="{StaticResource PageStyle}"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:model="using:MasterDetails.Models"
xmlns:views="using:MasterDetails.Views"
mc:Ignorable="d">
<Page.Resources>
<DataTemplate x:Key="ItemTemplate" x:DataType="model:SampleOrder">
<Grid Height="64" Padding="0,8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<FontIcon Grid.Column="0" Tag="{x:Bind HashIdentIcon}" FontSize="40" Glyph="{x:Bind SymbolAsChar}" VerticalAlignment="Center" />
<StackPanel Grid.Column="1" Margin="12,0,0,0" VerticalAlignment="Center">
<TextBlock Text="{x:Bind Company}" Tag="{x:Bind HashIdentTitle}" Style="{ThemeResource ListTitleStyle}"/>
<TextBlock Text="{x:Bind Status}" Style="{StaticResource ListSubTitleStyle}"/>
</StackPanel>
</Grid>
</DataTemplate>
<DataTemplate x:Key="DetailsTemplate">
<views:MasterDetailDetailControl MasterMenuItem="{Binding}"/>
</DataTemplate>
<DataTemplate x:Key="NoSelectionContentTemplate">
<TextBlock x:Uid="MasterDetail_NoSelection" Style="{StaticResource ListNoSelectionTextStyle}" />
</DataTemplate>
</Page.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition x:Name="TitleRow" Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock
x:Uid="MasterDetail_Title"
x:Name="TitlePage"
Margin="12,0,12,7"
Style="{StaticResource PageTitleStyle}" />
<controls:MasterDetailsView
Grid.Row="1"
x:Name="MasterDetailsViewControl"
ItemsSource="{x:Bind SampleItems}"
SelectedItem="{x:Bind Selected, Mode=OneWay}"
ItemTemplate="{StaticResource ItemTemplate}"
DetailsTemplate="{StaticResource DetailsTemplate}"
NoSelectionContentTemplate="{StaticResource NoSelectionContentTemplate}"
BorderBrush="Transparent">
<controls:MasterDetailsView.MasterCommandBar>
<CommandBar HorizontalAlignment="Left">
<AppBarButton Icon="Refresh" Label="Refresh"/>
<AppBarButton Icon="Add" Label="Add"/>
</CommandBar>
</controls:MasterDetailsView.MasterCommandBar>
<controls:MasterDetailsView.DetailsCommandBar>
<CommandBar HorizontalAlignment="Left">
<AppBarButton Icon="Edit" Label="Edit"/>
</CommandBar>
</controls:MasterDetailsView.DetailsCommandBar>
</controls:MasterDetailsView>
</Grid>
</Page>
命令栏位于底部(分别位于主面板和详细面板的底部)。我想让它们在顶部。我怎样才能做到这一点?
我尝试将主命令栏放在 MasterDetailsView 之外,将详细命令栏放在 MasterDetailDetailControl.xaml 中的滚动查看器之前,但这看起来不太好,并且占用了不必要的空间。