GridViewRowPresenter Class

Represents an object that specifies the layout of a row of data.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

public class GridViewRowPresenter : GridViewRowPresenterBase
<GridViewRowPresenter .../>

The GridViewRowPresenter and GridViewHeaderRowPresenter classes support the GridView view mode for a ListView control.

The following example shows how to use a GridViewRowPresenter to style rows in a ListView control. For the complete sample, see ListView with Styled ListViewItems Sample.

<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
			      xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>

  <StackPanel.Resources>	
    <XmlDataProvider x:Key="MyData" XPath="/Info">
      <x:XData>
        <Info xmlns="">
          <Song Name="Song1" Time="3:54" Artist="Singer1" 
              Rating="3" Disk="Disk1" />
          <Song Name="Song2" Time="4:31" Artist="Singer2" 
              Rating="4" Disk="Disk3"/>
          <Song Name="Song3" Time="5:06" Artist="Singer3" 
              Rating="5" Disk="Disk1" />
          <Song Name="Song4" Time="4:18" Artist="Singer3" 
              Rating="2" Disk="Disk2" />
          <Song Name="Song5" Time="6:15" Artist="Singer1" 
              Rating="5" Disk="Disk3" />
        </Info>
      </x:XData>
    </XmlDataProvider>

    <ControlTemplate x:Key="Default" TargetType='{x:Type ListViewItem}'>
      <StackPanel Background="Beige">
        <GridViewRowPresenter Content="{TemplateBinding Content}"
           Columns="{TemplateBinding GridView.ColumnCollection}"/>
      </StackPanel>
    </ControlTemplate>


    <ControlTemplate x:Key="StronglyRecommended" 
                     TargetType='{x:Type ListViewItem}'>
      <StackPanel Background="Beige">
        <GridViewRowPresenter Content="{TemplateBinding Content}"
           Columns="{TemplateBinding GridView.ColumnCollection}"/>
        <TextBlock Background="LightBlue" Text="Strongly Recommended" />
      </StackPanel>
    </ControlTemplate>

    <ControlTemplate x:Key="Recommended" TargetType='{x:Type ListViewItem}'>
      <StackPanel Background="Beige">
        <GridViewRowPresenter Content="{TemplateBinding Content}"
           Columns="{TemplateBinding GridView.ColumnCollection}"/>
        <TextBlock Background="LightBlue" Text="Recommended" />
      </StackPanel>
    </ControlTemplate>

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

  <ListView ItemsSource="{Binding Source={StaticResource MyData}, 
                          XPath=Song}" >

   <ListView.ItemContainerStyle>
    <Style TargetType="{x:Type ListViewItem}"  >
      <Setter Property="Template"
            Value="{StaticResource Default}"/>
      <Style.Triggers>
        <DataTrigger Binding="{Binding XPath=@Rating}" Value="5">
				<Setter Property="Template" 
                Value="{StaticResource StronglyRecommended}"/>
        </DataTrigger>
        <DataTrigger Binding="{Binding XPath=@Rating}" Value="4">
          <Setter Property="Template" 
                Value="{StaticResource Recommended}"/>
        </DataTrigger>
      </Style.Triggers>
	</Style>
  </ListView.ItemContainerStyle>

  <ListView.View>
    <GridView ColumnHeaderContainerStyle="{StaticResource MyHeaderStyle}">
      <GridViewColumn Header="Name" 
                      DisplayMemberBinding="{Binding XPath=@Name}" 
                      Width="100"/>
      <GridViewColumn Header="Time" 
                      DisplayMemberBinding="{Binding XPath=@Time}" 
                      Width="80"/>
      <GridViewColumn Header="Artist"  
                      DisplayMemberBinding="{Binding XPath=@Artist}" 
                      Width="80" />
      <GridViewColumn Header="Disk" 
                      DisplayMemberBinding="{Binding XPath=@Disk}"  
                      Width="100"/>
    </GridView>
  </ListView.View>
  </ListView>

</StackPanel>

More Code

How to: Display Data by Using GridViewRowPresenter This example shows how to use the GridViewRowPresenter and GridViewHeaderRowPresenter objects to display data in columns.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft