Style object based on binding bool attribute in wpf

后端 未结 2 781
天涯浪人
天涯浪人 2021-01-29 05:38

How can change the fill color of an object I\'m being to in my mvvm setup using xaml in wpf. I want to change the fill color to red when the attribute being bound to is set to

2条回答
  •  野的像风
    2021-01-29 06:17

    First of all you don't need any Binding for what you are trying to do. DataTrigger is enough. In the example below IsCyan is a boolean property of ViewModel. But Background of TextBlock is not bound at all.

               
                    
                        
                    
                
    

    But if at all you need Binding, solution by the user benPearce to use Converter is the way to go.

提交回复
热议问题