I have a UserControl and it contains a Button. Now, in some Windows I don’t want to show this Button. To achieve this I see two options.
- Create a DP.
- Bind directly with the viewModel’s property instead of creating DP.
Which of the above 2 options should be used?
UPDATE:
I found third way as well.
I am passing false in the CanCommandExecute of the binded Command which will make it’s IsEnabled to false.
I am using IsEnabled with Visibility using Converter.
How abt this solution?
Following should be the order of consideration
1. DP -> cleaner approach
2. If not DP, then CanCommandExecute -> Only purpose of this mechanism is to provide enable/disable support of Command handling
3. If not DP, CanCommandExecute, Normal property on VM (with BooleanToVisibilityConverter). This should not be preferred ( especially if there are multiple controls there are required to be enabled/disabled).