0

我使用 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 中的滚动查看器之前,但这看起来不太好,并且占用了不必要的空间。

4

1 回答 1

1

你需要重新模板MasterDetailsView

  1. 您可以从MasterDetailsView.xaml获取默认模板
  2. 更改行顺序<Grid.RowDefinitions>

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    
  3. MasterList更改toGrid.Row="2"MasterCommandBarPanelto的行号Grid.Row="1"

    <Grid x:Name="MasterPanel"
          Width="{TemplateBinding MasterPaneWidth}"
          Background="{TemplateBinding MasterPaneBackground}"
          BorderBrush="{TemplateBinding BorderBrush}"
          BorderThickness="0,0,1,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <ContentPresenter x:Name="HeaderContentPresenter"
                          Margin="12,0"
                          x:DeferLoadStrategy="Lazy"
                          Content="{TemplateBinding MasterHeader}"
                          ContentTemplate="{TemplateBinding MasterHeaderTemplate}"
                          Visibility="Collapsed" />
        <Grid x:Name="MasterCommandBarPanel" Grid.Row="1"></Grid>
        <ListView x:Name="MasterList"
                  Grid.Row="2"
                  IsTabStop="False"
                  ItemContainerStyle="{TemplateBinding ItemContainerStyle}"
                  ItemTemplate="{TemplateBinding ItemTemplate}"
                  ItemTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                  ItemsSource="{TemplateBinding ItemsSource}"
                  SelectedItem="{Binding SelectedItem, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" />
    </Grid>
    

做同样的事情DetailsPanel

于 2018-03-04T20:37:42.033 回答