2016-10-10 104 views
0

目前,我们有以下型号:重新评估命令CanExecute

public class Model : ModelBase 
{ 
    public Model() 
    { 
     ChildModel = new ChildModel(); 
    } 

    public string FirstName 
    { 
     get { return GetValue<string>(FirstNameProperty); } 
     set { SetValue(FirstNameProperty, value); } 
    } 

    public static readonly PropertyData FirstNameProperty = RegisterProperty("FirstName", typeof(string), string.Empty); 

    public ChildModel ChildModel 
    { 
     get { return GetValue<ChildModel>(ChildModelProperty); } 
     set { SetValue(ChildModelProperty, value); } 
    } 

    public static readonly PropertyData ChildModelProperty = RegisterProperty("ChildModel", typeof(ChildModel), null); 
} 

public class ChildModel : ModelBase 
{ 
    public static readonly PropertyData TestStringProperty = RegisterProperty("TestString", typeof(string), null); 

    public string TestString 
    { 
     get { return GetValue<string>(TestStringProperty); } 
     set { SetValue(TestStringProperty, value); } 
    } 
} 

我们使用一个模型,我们的视图模型

[Model] 
public Model AModel 
{ 
    get { return GetValue<Model>(AModelProperty); } 
    private set { SetValue(AModelProperty, value); } 
} 

public static readonly PropertyData AModelProperty = RegisterProperty("Prescription", typeof(Model)); 

有一个命令我们的视图模型与CanExecute功能。 我希望CanExecute在模型或ChildModel中的任何属性发生更改时重新评估。

有没有简单的方法来做到这一点?

(请注意,我们的实际生产模式具有多个子模式,并列出包含其他ModelBases)

我目前挂接到所有的所有子模型的PropertyChanged事件做,但是这似乎是一个肮脏的方式做到这一点。

回答

1

您需要编写自己的“观看机制”。您可以在Catel中使用ChangeNotificationWrapper

无论何时更新儿童模型,您都可以致电ViewModelCommandManager.InvalidateCommands(true)