I have two combo boxes in a form and a button. What i want to do is enable the button only if both the combo boxes have values selected in them.
My xaml
<Button Content="Generate Report"
Command="{Binding GenerateReportCommand}"
Margin="30,250,0,0">
<ComboBox Name="combo1"
ItemsSource="{Binding BannerValues}"
SelectedItem="{Binding item1}">
<ComboBox Name="combo2"
ItemsSource="{Binding BannerValues}"
SelectedItem="{Binding item2}">
I have a view model where all my bindings are defined.
class DataSource : INotifyPropertyChanged
{
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
public DataSource()
{
item1= load();
item2=load();// have some custome function to load the values for combobox
}
public ICommand GenerateReportCommand
{
get
{
return new CommandHandler(() => GenerateReport(item1,item2), true);
}
}
I have a separate class for commandhandler and will be in a seaprate file.
public class CommandHandler : ICommand
{
private Action _action;
private bool _canExecute;
public CommandHandler(Action action, bool canExecute)
{
_action = action;
_canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return _canExecute;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
_action();
}
}
how do i disable/enable the button based on the two combo boxes. Searching in the internet found that we can do using multidatatrigger. But i want to achieve using this command hanlder canexecute function