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.
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.
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?
just have a look at this
Is it better to use DataTrigger instead of a databinding?
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.
精彩评论