First row style in WPF Datagrid

I would like to change the style of the first row (only) in WPF Datagrid, but did not find how to do it. I wondered about creating a trigger, something like this:

<Style TargetType="{x:Type dg:DataGridRow}">
    <Style.Triggers>
        <Trigger Property="SelectedIndex" Value="0">
            <Setter Property="Background" Value="Red"/>
        </Trigger>
    </Style.Triggers>
</Style>

But of course, this will not work, because the DataGridRow does not have the SelectedIndex property. I also had some attempts to do this in my code, but I could not get it to work.

It seems that something that was pretty simple, but I could not handle it, so any advice would be most appreciated.

Thanks, Will

+3
source share
2 answers

, IValueConverter, , Style, ( ). DataGrid ?

:

public class StyleConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        Style style1 = App.Current.FindResource("RowStyle1") as Style;
        Style style2 = App.Current.FindResource("RowStyle2") as Style;

        List<object> items = parameter as List<object>;

        if (items[0] == value)
        {
            return style1;
        }

        return style2;
    }
}

, , , , !

, , !

+1

Source: https://habr.com/ru/post/1718908/


All Articles