TableView.RowStyle Property
Gets or sets the style applied to data rows. This is a dependency property.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v20.2.dll
NuGet Packages: DevExpress.WindowsDesktop.Wpf.Grid.Core, DevExpress.Wpf.Grid.Core
Declaration
Property Value
Type | Description |
---|---|
Style | A Style object that is the style applied to data rows. |
Remarks
The RowStyle property specifies the style that groups together properties, resources, and event handlers and shares them between instances of the GridRowContent type.
Target Type:
Optimized mode | Non-optimized mode |
---|---|
DevExpress.Xpf.Grid.RowControl | GridRowContent |
Refer to the following topic for more information: Appearance Customization.
Data Binding
Row elements contain RowData objects in their DataContext.
Use the following binding paths to access cell values and ViewModel properties:
Row.[YourPropertyName]
- access a property of an object in the ItemsSource collection;DataContext.[FieldName]
- access a column value;View.DataContext.[YourPropertyName]
- access a property in a grid’s ViewModel.
Note
The complete sample project is available in the following repository: https://github.com/DevExpress-Examples/how-to-build-binding-paths-in-gridcontrol-rows.
Example
This example demonstrates how to use the View's RowStyle and CellStyle properties to apply custom styles to the focused row and cell. To identify whether the row and cell are focused, the attached IsFocusedRow and IsFocusedCell properties are used.
<Window x:Class="DXGrid_ChangeRowAppearance.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxgt="http://schemas.devexpress.com/winfx/2008/xaml/grid/themekeys"
Title="Window1" Height="300" Width="505">
<Window.Resources>
<Style x:Key="FocusedCellStyle" TargetType="dxg:LightweightCellEditor">
<Style.Triggers>
<Trigger Property="dxg:DataViewBase.IsFocusedCell" Value="True">
<Setter Property="Background" Value="Green" />
<Setter Property="Foreground" Value="Yellow" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="FocusedRowStyle" TargetType="dxg:RowControl">
<Style.Triggers>
<Trigger Property="dxg:DataViewBase.IsFocusedRow" Value="True">
<Setter Property="Background" Value="Gray" />
<Setter Property="Foreground" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<dxg:GridControl x:Name="grid" AutoGenerateColumns="AddNew">
<dxg:GridControl.View>
<dxg:TableView AutoWidth="True" ShowGroupPanel="False"
AllowGrouping="False"
CellStyle="{StaticResource FocusedCellStyle}"
RowStyle="{StaticResource FocusedRowStyle}" />
</dxg:GridControl.View>
</dxg:GridControl>
</Grid>
</Window>
using System.Windows;
using System.Collections.Generic;
namespace DXGrid_ChangeRowAppearance {
public partial class Window1 : Window {
public Window1() {
InitializeComponent();
grid.ItemsSource = Products.GetData();
}
public class Products {
public static List<Product> GetData() {
List<Product> data = new List<Product>();
data.Add(new Product() { ProductName = "Chai",
UnitPrice = 18, UnitsOnOrder = 10 });
data.Add(new Product() { ProductName = "Ipoh Coffee",
UnitPrice = 36.8, UnitsOnOrder = 12 });
data.Add(new Product() { ProductName = "Outback Lager",
UnitPrice = 12, UnitsOnOrder = 25 });
data.Add(new Product() { ProductName = "Boston Crab Meat",
UnitPrice = 18.4, UnitsOnOrder = 18 });
data.Add(new Product() { ProductName = "Konbu",
UnitPrice = 6, UnitsOnOrder = 24 });
return data;
}
}
public class Product {
public string ProductName { get; set; }
public double UnitPrice { get; set; }
public int UnitsOnOrder { get; set; }
}
}
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the RowStyle property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.