Back to Devexpress

PropertyGridControl.RowStyleSelector Property

wpf-devexpress-dot-xpf-dot-propertygrid-dot-propertygridcontrol-5c73748d.md

latest3.7 KB
Original Source

PropertyGridControl.RowStyleSelector Property

Gets or sets an object that chooses a RowStyle based on custom logic. This is a dependency property.

Namespace : DevExpress.Xpf.PropertyGrid

Assembly : DevExpress.Xpf.PropertyGrid.v25.2.dll

NuGet Package : DevExpress.Wpf.PropertyGrid

Declaration

csharp
public StyleSelector RowStyleSelector { get; set; }
vb
Public Property RowStyleSelector As StyleSelector

Property Value

TypeDescription
StyleSelector

A StyleSelector descendant that chooses a style based on custom logic.

|

Remarks

The RowStyleSelector property allows you to apply a RowStyle based on a condition.

The following code sample applies a style to a row with today’s date:

csharp
public class RowStyleSelector : StyleSelector {
    public Style BDRowStyle { get; set; }
    public override Style SelectStyle(object item, DependencyObject container) {
        RowData rowData = item as RowData;
        if (rowData != null && rowData.Header == nameof(Customer.BirthDate)) {
            DateTime date = (DateTime)rowData.Value;
            DateTime today = DateTime.Today;
            if (date.Day == today.Day && date.Month == today.Month) {
                return BDRowStyle;
            }
        }
        return base.SelectStyle(item, container);
    }
}
vb
Public Class RowStyleSelector
    Inherits StyleSelector

    Public Property BDRowStyle As Style

    Public Overrides Function SelectStyle(ByVal item As Object, ByVal container As DependencyObject) As Style
        Dim rowData As RowData = TryCast(item, RowData)

        If rowData IsNot Nothing AndAlso rowData.Header = NameOf(Customer.BirthDate) Then
            Dim date As DateTime = CType(rowData.Value, DateTime)
            Dim today As DateTime = DateTime.Today

            If date.Day = today.Day AndAlso date.Month = today.Month Then
                Return BDRowStyle
            End If
        End If

        Return MyBase.SelectStyle(item, container)
    End Function
End Class
xaml
<Window.Resources>
    <Style x:Key="bdRowStyle" TargetType="dxprg:RowControl">
        <Setter Property="Background" Value="Orange"/>
        <Setter Property="Foreground" Value="White"/>
    </Style>

    <local:RowStyleSelector x:Key="rowStyleSelector"
                            BDRowStyle="{StaticResource bdRowStyle}"/>
</Window.Resources>
<dxprg:PropertyGridControl ...
                           RowStyleSelector="{StaticResource rowStyleSelector}"/>

Refer to the following help topic for more information on appearance properties: Appearance Customization.

See Also

PropertyGridControl Class

PropertyGridControl Members

DevExpress.Xpf.PropertyGrid Namespace