本文档已存档,并且将不进行维护。

GridViewRowPresenter 类

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

命名空间: System.Windows.Controls
程序集: PresentationFramework(在 presentationframework.dll 中)
XML 命名空间:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public class GridViewRowPresenter : GridViewRowPresenterBase
public class GridViewRowPresenter extends GridViewRowPresenterBase
public class GridViewRowPresenter extends 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.

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

更多代码

How to: Display Data by Using GridViewRowPresenter

This example shows how to use the GridViewRowPresenter and GridViewHeaderRowPresenter objects to display data in columns.

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Media.Visual
         System.Windows.UIElement
           System.Windows.FrameworkElement
             System.Windows.Controls.Primitives.GridViewRowPresenterBase
              System.Windows.Controls.GridViewRowPresenter

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

Windows Vista、Microsoft Windows XP SP2 和 Windows Server 2003 SP1 支持 Microsoft .NET Framework 3.0。

.NET Framework

受以下版本支持:3.0
显示: