MasterDetailsView中的CommandBar放置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MasterDetailsView中的CommandBar放置相关的知识,希望对你有一定的参考价值。

我使用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>

命令栏位于底部(分别为master和details面板)。我想让他们在顶部。我怎么能做到这一点?

我尝试将主命令栏放在MasterDetailsView和详细命令栏之外,就在MasterDetailDetailControl.xaml内的scrollviewer之前,但这看起来并不好,占用了不必要的空间。

答案

你需要重新模板MasterDetailsView

  1. 您可以从MasterDetailsView.xaml获取默认模板
  2. 更改<Grid.RowDefinitions>中的行顺序 <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions>
  3. MasterList的行号更改为Grid.Row="2",将MasterCommandBarPanel更改为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做同样的事情

以上是关于MasterDetailsView中的CommandBar放置的主要内容,如果未能解决你的问题,请参考以下文章

sql 使用T-SQL将一串comman分隔的int分成Ints表

powershell 清理和交叉连接包含具有由comman或换行符分隔的多个条目的单元格的excel表

vi编辑文件保存后,提示""vimrc" E212: Can't open file for writing Press ENTER or type comman

将 Button 的可见性绑定到 ViewModel 中的 bool 值

将图像加载到 Gridview

docker中的Jenkins修改密码或者忘记密码