WPF XAML - DataTriggers or ValueConverters? Best practice

前端 未结 2 739
不思量自难忘°
不思量自难忘° 2021-01-23 07:14

I have a Window with a TextBlock. This TextBlock has to show the value \"R\" if the binded value is 0 or \"M\" if the binded value is 1.

I have

2条回答
  •  情歌与酒
    2021-01-23 07:23

    In most of the scenarios triggers can perform the same work as any converter but Converters can have custom/business logic.

    One limitation of Triggers is that Setters in your DataTriggers can only change properties of your UI elements; so, you can't update your ViewModels property with triggers, that's where Converters win, remember the ConvertBack method.

    So in short Triggers can only perform OneWay operations whereas Converters can perform TwoWay operations

提交回复
热议问题