Compartilhar via


Como exibir dados usando GridViewRowPresenter

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

Exemplo

O exemplo a seguir mostra como especificar um que exibe o DayOfWeek e de um DateTimeGridViewColumnCollection objeto usando GridViewRowPresenter e YearGridViewHeaderRowPresenter objetos. O exemplo também define um para o Header de um GridViewColumnStyle .

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

Confira também