2016-10-10 99 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)