[英]CanExecute not triggered
In my UWP the CanExecute
handler doesn't get triggered. 在我的UWP中,
CanExecute
处理程序不会被触发。 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 mtControls:DataGrid
映射到MyToolkit DataGrid,可以在以下位置找到: https : //github.com/MyToolkit/MyToolkit/tree/master/src/MyToolkit.Extended/Controls/DataGrid
Does anyone have an answer why it doesn't get called? 有人有答案为什么不被调用吗?
I encountered the same issue using GalaSoft.MvvmLight. 我在使用GalaSoft.MvvmLight时遇到了相同的问题。 Here is a workarround (just use the RaiseCanExecuteChanged() function of the RelayCommand):
这是一个工作环境(只需使用RelayCommand的RaiseCanExecuteChanged()函数):
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. 问题是,根据设计,CommandManager在UWP应用中不存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.