Partilhar via


Como: Exibir dados usando GridViewRowPresenter

Este exemplo mostra como usar os objetos GridViewRowPresenter e GridViewHeaderRowPresenter para exibir dados em colunas.

Exemplo

O exemplo a seguir mostra como especificar um GridViewColumnCollection que exibe o DayOfWeek e o Year de um objeto DateTime usando GridViewRowPresenter e GridViewHeaderRowPresenter objetos. O exemplo também define um Style para o Header de um GridViewColumn.

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
        xmlns:sys="clr-namespace:System;assembly=mscorlib">
 
  <Window.Resources>

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

    <GridViewColumnCollection x:Key="gvcc">
      <GridViewColumn Header="Year" 
                      DisplayMemberBinding="{Binding Year}" 
                      Width="80"/>
      <GridViewColumn Header="Day"  
                      DisplayMemberBinding="{Binding DayOfWeek}" 
                      Width="80" />

    </GridViewColumnCollection>

  </Window.Resources>
  
  <StackPanel>
    <GridViewHeaderRowPresenter Name="hrp" Columns="{StaticResource gvcc}"  
                                ColumnHeaderContainerStyle=
                                 "{StaticResource MyHeaderStyle}" />

    <GridViewRowPresenter Columns="{StaticResource gvcc}" >
      <GridViewRowPresenter.Content>
        <sys:DateTime>2005/2/1</sys:DateTime>
      </GridViewRowPresenter.Content>
     </GridViewRowPresenter>
    <GridViewRowPresenter Columns="{StaticResource gvcc}" >
      <GridViewRowPresenter.Content>
        <sys:DateTime>2006/10/12</sys:DateTime>
      </GridViewRowPresenter.Content>
    </GridViewRowPresenter>
  </StackPanel>

</Window>

Ver também