WPF:将GridView标题溢出为两行,其中底行分为两列

时间:2008-11-24 11:07:11

标签: wpf listview gridviewheader

我试图将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的外观

1 个答案:

答案 0 :(得分: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>