WPF Datagrid trigger row colour based on value

后端 未结 1 1561
无人及你
无人及你 2021-01-06 01:30

I have a WPF application that contains a datagrid. The datagrid is bound to my object OrderBlock which contains a List of type Orders.



        
1条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-06 02:14

    Do you need to change the behaviour of the DataGridRow, or is it sufficient to alter the style?

    If changing the row highlighting based on a property is all you need, you should be able to just use a simpler Style, something like this:

        
        
            
            
        
    
        
        
    

    You should be able to apply the style when required in a DataGrid by using your style as a StaticResource for the RowStyle property:

    
    

    Edit:

    If you want to retain the rest of your styling and use a control template, you can place your DataTrigger in your ControlTemplate.Triggers, you'll also have to supply a TargetName property, to specify the element you wish the trigger to act on, so using my above brush, and your initial code:

    
    
    

    Where DGR_Border is the name you had given your border with the existing gradient.

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