2

我正在尝试将 gridViewColumn 分成两行。我使用 listView 的默认样式。将列标题分成两行没有问题,但似乎内容被放置在原始样式上,边框等隐藏在我自定义的 gridViewHeader 内容下。代码如下所示:

<GridViewColumnHeader>
    <GridViewColumnHeader.Template>
        <ControlTemplate>
            <Grid VerticalAlignment="Center" HorizontalAlignment="Center">
                <Grid ShowGridLines="False" VerticalAlignment="Center" HorizontalAlignment="Center">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0" Text="SomeHeaderText" HorizontalAlignment="Center"/>
                    <Grid Grid.Row="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0" Text="SubHeaderText1" Padding="5"  HorizontalAlignment="Center" />
                            <TextBlock Grid.Column="1" Text="SubHeaderText1" Padding="5" HorizontalAlignment="Center" />                                                
                        </Grid>
                    </Grid>
            </Grid>
        </ControlTemplate>
    </GridViewColumnHeader.Template>
</GridViewColumnHeader> 

任何人都知道如何像这个例子一样裁剪 GridViewHeader 并保持 GridViewHeader 的外观

4

1 回答 1

1

您应该将自定义模板作为 GridViewColumnHeader 的内容,而不是作为其模板。这是正确的 XAML:

<GridViewColumnHeader>
   <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
      <Grid HorizontalAlignment="Center" VerticalAlignment="Center" ShowGridLines="False">
         <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
         </Grid.RowDefinitions>
         <TextBlock Grid.Row="0" HorizontalAlignment="Center" Text="SomeHeaderText"/>
         <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
               <ColumnDefinition Width="*"/>
               <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <TextBlock
               Grid.Column="0"
               HorizontalAlignment="Center"
               Padding="5"
               Text="SubHeaderText1"/>
            <TextBlock
               Grid.Column="1"
               HorizontalAlignment="Center"
               Padding="5"
               Text="SubHeaderText1"/>
         </Grid>
      </Grid>
   </Grid>
</GridViewColumnHeader>
于 2008-11-24T20:00:59.630 回答