Search code examples
wpfdatatrigger

WPF DataTrigger vs .Net Property


I am using MVVM pattern and have a scenario where I need to hide a control based on some functional logic.

I have two options to handle it.

  1. I can create a boolean property on view model and bind this with corresponding control to handle visibility and this property gets set based on some functional logic.

  2. I can use a DataTrigger on control to handle visibility on XAML itself which use same functional logic here. (This functional logic are easy to access on XAML)

Question - Which is the correct way to handle it in terms of performance and maintainability etc. in WPF?


Solution

  • I would say option 1: Say u want to snap on a Silverlight View. Then you don't have to go and create the trigger in the Silverlight View.

    So the first option will be the best pattern according to MVVM.