Compartilhar via


Como: Exibir dados usando GridViewRowPresenter

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

Exemplo

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

<Window xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x='https://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>

Consulte também

Conceitos

GridView Overview

Referência

GridViewHeaderRowPresenter

GridViewRowPresenter

GridViewColumnCollection