下面是一个非常简单的Prism.Wpf示例,DelegateCommand其中包含两个Execute和CanExecute委托.
假设这CanExecute取决于某些属性.看起来Prism's DelegateCommand不会CanExecute在这个属性发生变化时自动重新评估条件,就像RelayCommand其他MVVM框架一样.相反,您必须在属性设置器中显式调用RaiseCanExecuteChanged().这会在任何非平凡的视图模型中导致大量重复代码.
有没有更好的办法?
ViewModel:
using System;
using Prism.Commands;
using Prism.Mvvm;
namespace PrismCanExecute.ViewModels
{
public class MainWindowViewModel : BindableBase
{
private string _title = "Prism Unity Application";
public string Title
{
get { return _title; }
set { SetProperty(ref _title, value); }
}
private string _name;
public string Name
{
get { return _name; }
set
{
SetProperty(ref _name, value);
// Prism doesn't track …Run Code Online (Sandbox Code Playgroud)