Change DataGrid cell colour based on values

前端 未结 8 1481
栀梦
栀梦 2020-11-22 08:48

I have got a WPF datagrid and I want diffrent cell colours according to values. I have got below code on my xaml

Style TargetType=\"DataGridCell\"

8条回答
  •  -上瘾入骨i
    2020-11-22 09:32

            // Example: Adding a converter to a column (C#)
            Style styleReading = new Style(typeof(TextBlock));
            Setter s = new Setter();
            s.Property = TextBlock.ForegroundProperty;
            Binding b = new Binding();
            b.RelativeSource = RelativeSource.Self;
            b.Path = new PropertyPath(TextBlock.TextProperty);
            b.Converter = new ReadingForegroundSetter();
            s.Value = b;
            styleReading.Setters.Add(s);
            col.ElementStyle = styleReading;
    

提交回复
热议问题