Reputation: 2002
In my UWP the CanExecute
handler doesn't get triggered. Here is my code:
RelayCommand
EditWorkItemEntry = new RelayCommand(async () =>
{
var diag = new EditWorkItemEntryDialog(SelectedWorkItem);
await diag.ShowAsync();
await ReloadWorkItems();
}, () =>
{
return SelectedWorkItem != null;
});
The code that uses the command:
<mt:MtPage.BottomAppBar>
<CommandBar>
<AppBarButton Icon="Edit" x:Uid="EditWorkItemEntry" Command="{x:Bind ViewModel.EditWorkItemEntry, Mode=OneWay}" />
</CommandBar>
</mt:MtPage.BottomAppBar>
And the code that should trigger it:
<mtControls:DataGrid ItemsSource="{Binding WorkItems}" SelectedItem="{x:Bind ViewModel.SelectedWorkItem, Mode=OneWay}">
<!-- More definition logic -->
</mtControls:DataGrid>
mtControls:DataGrid
is mapped to MyToolkit DataGrid, it can be found here: https://github.com/MyToolkit/MyToolkit/tree/master/src/MyToolkit.Extended/Controls/DataGrid
Does anyone have an answer why it doesn't get called?
Upvotes: 0
Views: 119
Reputation: 297
I encountered the same issue using GalaSoft.MvvmLight. Here is a workarround (just use the RaiseCanExecuteChanged() function of the RelayCommand):
private MyClass _selectedWorkItem;
public MyClass SelectedWorkItem
{
get { return _selectedWorkItem; }
set
{
_selectedWorkItem = value;
EditWorkItemEntry.RaiseCanExecuteChanged();
}
}
The problem is that the CommandManager is not present in UWP apps by design.
Upvotes: 2