How do I programatically change datagrid row color in WPF?

前端 未结 1 1224
粉色の甜心
粉色の甜心 2021-01-25 15:43

I was wondering if this possible. I have this datagrid contains 3 columns and 2 rows. What I want is to change the background of the URL column on my datagrid according to the d

1条回答
  •  囚心锁ツ
    2021-01-25 16:04

    Your rowColor should not return a string (i would rename it to RowColor since it is public), just return the actual colour-brushes instead. (Your colours are wrong by the way, the first is opaque black and the second is transparent blue)

    e.g.

    public Brush rowColor { get; set; }
    
    data1.rowColor = Brushes.Red;
    data2.rowColor = Brushes.Blue;
    

    If you really need to parse from string you could use a value converter or the standard conversion that is used when parsing Xaml.

    Besides that i am not sure if binding those properties to Foreground of the column will work.

    0 讨论(0)
提交回复
热议问题