C# CanExecute未触发

C# CanExecute未触发,c#,uwp,C#,Uwp,在我的UWP中,CanExecute处理程序不会被触发。这是我的密码: 中继通信 EditWorkItemEntry = new RelayCommand(async () => { var diag = new EditWorkItemEntryDialog(SelectedWorkItem); await diag.ShowAsync(); await ReloadWorkItems(); }, () => { return SelectedWor

在我的UWP中,
CanExecute
处理程序不会被触发。这是我的密码:

中继通信

EditWorkItemEntry = new RelayCommand(async () =>
{
    var diag = new EditWorkItemEntryDialog(SelectedWorkItem);
    await diag.ShowAsync();
    await ReloadWorkItems();
}, () =>
{
    return SelectedWorkItem != null;
});
使用该命令的代码:

<mt:MtPage.BottomAppBar>
  <CommandBar>
    <AppBarButton Icon="Edit" x:Uid="EditWorkItemEntry" Command="{x:Bind ViewModel.EditWorkItemEntry, Mode=OneWay}" />
  </CommandBar>
</mt:MtPage.BottomAppBar>


有人知道它为什么没有被调用吗?

我在使用GalaSoft.MvvmLight时遇到了同样的问题。下面是一个workaround(只需使用RelayCommand的raisecancecutechanged()函数):


问题是,根据设计,CommandManager不存在于UWP应用程序中。

我在使用GalaSoft.MvvmLight时遇到了相同的问题。下面是一个workaround(只需使用RelayCommand的raisecancecutechanged()函数):

问题在于,根据设计,CommandManager在UWP应用程序中并不存在

<mtControls:DataGrid ItemsSource="{Binding WorkItems}" SelectedItem="{x:Bind ViewModel.SelectedWorkItem, Mode=OneWay}">
    <!-- More definition logic -->
</mtControls:DataGrid>
private MyClass _selectedWorkItem;

public MyClass SelectedWorkItem
{
  get { return _selectedWorkItem; }
  set
  {
     _selectedWorkItem = value;
     EditWorkItemEntry.RaiseCanExecuteChanged();
  }
}