Export (0) Print
Expand All

GridViewColumn.HeaderContainerStyle Property

Gets or sets the style to use for the header of the GridViewColumn.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public Style HeaderContainerStyle { get; set; }
/** @property */
public Style get_HeaderContainerStyle ()

/** @property */
public void set_HeaderContainerStyle (Style value)

public function get HeaderContainerStyle () : Style

public function set HeaderContainerStyle (value : Style)

<object HeaderContainerStyle="{ResourceExtension StyleResourceKey}"/>
 ResourceExtension  One of the following: StaticResource, or DynamicResource. See Resources Overview.  StyleResourceKey  The key that identifies the style being requested. The key refers to an existing resource in a ResourceDictionary. 

Property Value

The Style that defines the display properties for the column header. The default value is a null reference (Nothing in Visual Basic).

Identifier field

HeaderContainerStyleProperty

Metadata properties set to true

None

The HeaderContainerStyle property and the HeaderTemplate property can together define property values and the visual tree for column header content. The HeaderContainerStyle property can also specify the visual tree by defining a ControlTemplate.

Properties that define the content, layout, and style of a column header are found in many related classes, and some of these properties have functionality that is similar or the same. For more information, see GridView Column Header Styles and Templates Overview.

When you set a style, some restrictions apply. For more information, see the Styles Overview.

The following example shows how to define a HeaderContainerStyle that specifies display properties for a column header. For the complete sample, see ListView implementing a GridView with Templates.

<Style x:Key="myHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
  <Setter Property="Background" Value="LightBlue"/>
</Style>

<GridViewColumn Header="Month" Width="80"
      HeaderContainerStyle="{StaticResource myHeaderStyle}"
      HeaderTemplate="{StaticResource myHeaderTemplate}"
      DisplayMemberBinding="{Binding Path=Month}"/>

The following example shows how to define a HeaderContainerStyle that defines display properties by using a ControlTemplate. For the complete sample, see ListView implementing a GridView with Templates.

<Style x:Key="myControlTemplateStyle" 
       TargetType="{x:Type GridViewColumnHeader}">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
        <Grid Background="LightBlue">
          <DockPanel HorizontalAlignment="Center"
                      VerticalAlignment="Center">
            <CheckBox></CheckBox>
            <TextBlock Text="{TemplateBinding Content}" 
                  FontSize="16" Foreground="DarkBlue"/>
          </DockPanel>
          <Canvas>
          <Thumb x:Name="PART_HeaderGripper"
                 Style="{StaticResource GridViewColumnHeaderGripper}"
                 Background="Transparent"
                 />
        </Canvas>
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

<GridView ColumnHeaderContainerStyle="{StaticResource 
                       myControlTemplateStyle}">
  <GridViewColumn Header="Year" Width="80"
        CellTemplate="{StaticResource myCellTemplateYear}"/>
  <GridViewColumn Header="Month" Width="80"
        CellTemplate="{StaticResource myCellTemplateMonth}"/>
  <GridViewColumn Header="Day" Width="80"
        CellTemplate="{StaticResource myCellTemplateDay}"/>
</GridView>

More Code

How to: Use Templates to Style a ListView That Uses GridView

This example shows how to use the DataTemplate and Style objects to specify the appearance of a ListView control that uses a GridView view mode.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft