I am using WPF with MVVM pattern. I have a button and I have two commands. Furthermore I have a checkbox. And I want to bind different command to the button, depending on the checkbox IsChecked or not, for example
If I click my button, it shows a message box;
if I check the checkbox and click my button, it shows a new window or something else..
I have a solution for this, but I think there can be better solution:
My ViewModel:
ICommand command1 { get; set; }
ICommand command2 { get; set; }
ICommand commandSelector
{
get
{
if (checkbox)
{
return command1;
}
else
{
return command2;
}
}
private set { }
}
My XAML:
<Button Label="DO" Command="{Binding commandSelector}"/>