2008-11-24 55 views
2

我試圖將一個gridViewColumn分隔成兩行。我使用listView的默認樣式。將列標題分隔成兩行沒有問題,但好像內容被放在原始樣式上,並且邊界等隱藏在我的自定義gridViewHeader內容下。代碼如下:WPF:Split GridView標題分成兩行,其中最下面一行分爲兩列。

<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> 

任何人知道如何cutomized的GridViewHeader像這樣的例子並保持GridViewHeader的外觀

回答

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>