Style first row in a WPF Datagrid

浪子不回头ぞ 提交于 2019-12-05 22:30:13

You might be able to create an IValueConverter to return your Style, either as a Style object or just a string representation (ie. the name of the style). Then you can bind the style property of your DataGrid to the converter and pass in the underlying list of items as a parameter to determine the index of the current item?

The converter might look something like this...

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

Not sure if this would work, I probably haven't explained it very well either!

I'm curious now, I might give this a try and see if I can get it to work!

I don't know of a way to do this, but it is possible to freeze a row. Does that suit your needs? The code in the following link might lead you to a solution on how to get access to a specific row so that you can apply a style to it.

http://blogs.msdn.com/vinsibal/archive/2008/10/31/wpf-datagrid-frozen-row-sample.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!