簡體   English   中英

CanExecute未觸發

[英]CanExecute not triggered

在我的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>

和應該觸發它的代碼:

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

mtControls:DataGrid映射到MyToolkit DataGrid,可以在以下位置找到: https//github.com/MyToolkit/MyToolkit/tree/master/src/MyToolkit.Extended/Controls/DataGrid

有人有答案為什么不被調用嗎?

我在使用GalaSoft.MvvmLight時遇到了相同的問題。 這是一個工作環境(只需使用RelayCommand的RaiseCanExecuteChanged()函數):

private MyClass _selectedWorkItem;

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

問題是,根據設計,CommandManager在UWP應用中不存在。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM