PrismでMVVMパターンを使用しています
モデルの ObservableCollection に要素のリストがあります。私のビューでは、ObservableCollection を Listview にバインドしてから、DoSomethingCommand という DelegateCommand にバインドされた 1 つのボタンを表示しようとしました。これは、Listview の各行に DoSomethingCommand を呼び出すボタンがあり、CommandParameter が要素の ID にバインドされていることを意味します。
制約: DoSomethingCommand は、要素のステータス フィールドを「完了」に変更します。要素が「完了」したら、DoSomethingCommand を呼び出すボタンを無効にする必要があります。
論理的には、コマンドを実装するときに canExecuteDoSomethingCommand デリゲートを用意するだけです。しかし、問題は、いつ、どのように DoSomethingCommand.RaiseCanExecuteChanged を発生させることができるかということです。BTW Element は、変更できないサード パーティの dll の一部ですが、既に INotifyPropertyChanged を実装しています。
<ListView BorderThickness="0" Width="Auto"
ItemsSource="{Binding ElementList}"
>
<ListView.View>
<GridView>
<GridViewColumn Header="Actions">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button Command="{Binding DataContext.DoSomethingCommand, RelativeSource={RelativeSource AncestorType={x:Type ListView}}}" CommandParameter="{Binding ID}" >Accept</Button>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
コマンドの実装
DoSomethingCommand = new DelegateCommand<string>(executeDoSomethingCommand, canExecuteDoSomethingCommand);