Specialization of the
Row that represents a row that contains a collection of
DataCells.
DataRows are the visual representation of the data items that are displayed in a grid's viewport.
Object Model
Syntax
Example
All examples in this topic assume that the grid is bound to the
Orders table of the Northwind database, unless stated otherwise.
The following example demonstrates how to alternate the appearance of data row styles using the IndexToOddConverter.
| XAML | Copy Code |
|---|
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"> <Grid.Resources> <xcdg:IndexToOddConverter x:Key="rowIndexConverter"/> <Style TargetType="{x:Type xcdg:DataRow}"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:DataGridVirtualizingPanel.ItemIndex), Converter={StaticResource rowIndexConverter}}" Value="True"> <Setter Property="Background"> <Setter.Value> <SolidColorBrush Color="LightGray" Opacity="0.1"/> </Setter.Value> </Setter> </DataTrigger> </Style.Triggers> </Style> <xcdg:DataGridCollectionViewSource x:Key="cvs_orders" Source="{Binding Source={x:Static Application.Current}, Path=Orders}"/> </Grid.Resources> <xcdg:DataGridControl x:Name="OrdersGrid" ItemsSource="{Binding Source={StaticResource cvs_orders}}"> </xcdg:DataGridControl> </Grid> |
The following example demonstrates how to changed the background color of a DataRow according to the value of one of its cells using DataTriggers.
| XAML | Copy Code |
|---|
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"> <Grid.Resources> <xcdg:DataGridCollectionViewSource x:Key="cvs_orders" Source="{Binding Source={x:Static Application.Current}, Path=Orders}"/> <Style TargetType="{x:Type xcdg:DataRow}"> <Style.Triggers> <DataTrigger Binding="{Binding Path=[EmployeeID]}" Value="1"> <Setter Property="Background" Value="Pink"/> </DataTrigger> <DataTrigger Binding="{Binding Path=[EmployeeID]}" Value="3"> <Setter Property="Background" Value="Blue"/> </DataTrigger> </Style.Triggers> </Style> </Grid.Resources> <xcdg:DataGridControl x:Name="OrdersGrid" ItemsSource="{Binding Source={StaticResource cvs_orders}}"/> </Grid> |
The following example demonstrates how to subscribe the MouseEnter and MouseLeave events of each DataRow using EventTriggers in an implicit style.
| XAML | Copy Code |
|---|
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"> <Grid.Resources> <xcdg:DataGridCollectionViewSource x:Key="cvs_orders" Source="{Binding Source={x:Static Application.Current}, Path=Orders}"/> <Style TargetType="{x:Type xcdg:DataRow}"> <EventSetter Event="MouseEnter" Handler="DataRowMouseEnter"/> <EventSetter Event="MouseLeave" Handler="DataRowMouseLeave"/> </Style> </Grid.Resources> <xcdg:DataGridControl x:Name="OrdersGrid" ItemsSource="{Binding Source={StaticResource cvs_orders}}" View="TableView.LunaNormalColorTheme"/> </Grid> |
The following example demonstrates how to display a row's visual index in its corresponding row selector by creating a style targeting the RowSelector type that displays the value of its ItemIndex property as its content. The style is then assigned to the RowSelector.RowSelectorStyle attached property, which is set by the implicit DataRow style.
| XAML | Copy Code |
|---|
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"> <Grid.Resources> <xcdg:DataGridCollectionViewSource x:Key="cvs_orders" Source="{Binding Source={x:Static Application.Current}, Path=Orders}" /> <Style x:Key="itemIndexSelectorStyle" TargetType="{x:Type xcdg:RowSelector}"> <Setter Property="Content" Value="{Binding RelativeSource={RelativeSource Self}, Path=ItemIndex}"/> </Style> <Style TargetType="{x:Type xcdg:DataRow}"> <Setter Property="xcdg:RowSelector.RowSelectorStyle" Value="{StaticResource itemIndexSelectorStyle}" /> </Style> </Grid.Resources> <xcdg:DataGridControl x:Name="OrdersGrid" ItemsSource="{Binding Source={StaticResource cvs_orders}}" /> </Grid> |
The following example demonstrates how to provide, through a style, a new ControlTemplate for DataRow objects. The columns that are contained in the grid will be limited to those specified in the ItemProperties of the DataGridCollectionViewSource.
| XAML | Copy Code |
|---|
<Grid> <Grid.Resources> <xcdg:DataGridCollectionViewSource x:Key="cvs_employees" Source="{Binding Source={x:Static Application.Current}, Path=Employees}" AutoCreateItemProperties="False"> <xcdg:DataGridCollectionViewSource.ItemProperties> <xcdg:DataGridItemProperty Name="LastName"/> <xcdg:DataGridItemProperty Name="FirstName"/> <xcdg:DataGridItemProperty Name="Photo"/> <xcdg:DataGridItemProperty Name="Title"/> <xcdg:DataGridItemProperty Name="Notes"/> <xcdg:DataGridItemProperty Name="EmployeeID"/> <xcdg:DataGridItemProperty Name="TitleOfCourtesy"/> <xcdg:DataGridItemProperty Name="HireDate"/> <xcdg:DataGridItemProperty Name="Extension"/> </xcdg:DataGridCollectionViewSource.ItemProperties> </xcdg:DataGridCollectionViewSource> <ControlTemplate x:Key="titleLessCell" TargetType="xcdg:DataCell"> <ContentPresenter Content="{xcdg:CellContentBinding}" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"/> </ControlTemplate> <Style x:Key="customCardViewDataRow" TargetType="{x:Type xcdg:DataRow}"> <Setter Property="Background" Value="Transparent"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type xcdg:DataRow}"> <Border x:Name="PART_RowFocusRoot" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"> <Grid> <StackPanel> <DockPanel> <!-- The photo is at the left. --> <Grid DockPanel.Dock="Left" Margin="3,4,2,2" MaxWidth="85" MaxHeight="85"> <xcdg:DataCell FieldName="Photo" Template="{StaticResource titleLessCell}"/> </Grid> <StackPanel Margin="8,0,0,0"> <StackPanel Orientation="Horizontal"> <xcdg:DataCell FieldName="TitleOfCourtesy" FontSize="16" Template="{StaticResource titleLessCell}"/> <TextBlock Text=" "/> <xcdg:DataCell FieldName="FirstName" FontSize="16" Template="{StaticResource titleLessCell}"/> <TextBlock Text=" "/> <xcdg:DataCell FieldName="LastName" FontSize="16" Template="{StaticResource titleLessCell}"/> </StackPanel> <xcdg:DataCell FieldName="Title" FontSize="14" Template="{StaticResource titleLessCell}"/> <Border BorderThickness="1" BorderBrush="#999999" Margin="0,2,0,2"/> <StackPanel x:Name="PART_CellsHost" Orientation="Vertical" Grid.IsSharedSizeScope="True"/> </StackPanel> </DockPanel> <Expander Header="Notes" Padding="5" TextElement.Foreground="{TemplateBinding Foreground}"> <xcdg:DataCell FieldName="Notes" Template="{StaticResource titleLessCell}"/> </Expander> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="FocusVisualStyle" Value="{x:Null}"/> </Style> </Grid.Resources> <xcdg:DataGridControl x:Name="OrdersGrid" ItemsSource="{Binding Source={StaticResource cvs_employees}}" ItemContainerStyle="{StaticResource customCardViewDataRow}" View="CardView"> <xcdg:DataGridControl.Columns> <xcdg:Column FieldName="Notes" TextWrapping="Wrap"/> </xcdg:DataGridControl.Columns> </xcdg:DataGridControl> </Grid> |
Remarks
Inheritance Hierarchy
Requirements
Supported Operating Systems: Windows Server 2003 Service Pack 1; Windows Vista; Windows XP Service Pack 2
See Also