I have two commands that I want to trigger via a button click. So I've created a CompositeCommand, registered my two commands with it, and bound to my button. My commands are DelegateCommands.
The problem is that the button is disabled and I can't enable it.
I've tried adding trivial CanExecute methods to the DeleteCommands, but that didn't fix it.
I've tried setting monitorCommandActivity to true in the CompositeCommand constructor.
I thought maybe it was disabling because my DelegateCommands have parameters and a CompositeCommand doesn't seem to be able to take any CommandParameters, but I eliminated the parameters in the DelegateCommands and that didn't fix the problem.
View.xaml:
<TextBlock Text="Theme:" />
<telerik:RadComboBox x:Name="_themeComboBox"
ItemsSource="{Binding ThemeList}"
DisplayMemberPath="Name"
SelectedItem="{Binding SelectedTheme, Mode=TwoWay}" />
<telerik:RadButton Content="Apply"
Command="{Binding ThemeApplyAndSaveCommand}" />
ViewModel.cs:
public class ViewModel
{
public ViewModel(ILogger logger, ...)
{
ThemeList = _userSettingsService.GetThemeList();
// Configure the theme Apply button to both select and save the theme
ThemeApplyAndSaveCommand.RegisterCommand(ThemeApplyCommand);
ThemeApplyAndSaveCommand.RegisterCommand(ThemeSaveCommand);
// Activate the user's preferred theme
SelectedTheme = _userSettingsService.GetThemePreference(securityContext.User);
ThemeApplyCommand.Execute();
logger.Debug(" ThemeApplyCommand.CanExecute: {canExecute}", ThemeApplyCommand.CanExecute());
logger.Debug(" ThemeSaveCommand.CanExecute: {canExecute}", ThemeSaveCommand.CanExecute());
logger.Debug(" ThemeApplyAndSaveCommand.CanExecute: {canExecute}", ThemeApplyAndSaveCommand.CanExecute(null));
}
public CompositeCommand ThemeApplyAndSaveCommand => new CompositeCommand();
public DelegateCommand ThemeApplyCommand => new DelegateCommand(ExecuteThemeApplyCommand);
public DelegateCommand ThemeSaveCommand => new DelegateCommand(ExecuteThemeSaveCommand);
private void ExecuteThemeApplyCommand()
{
...
}
private void ExecuteThemeSaveCommand()
{
...
}
}