2016-10-10 3 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); } 
    } 
} 

私たちは、CanExecute機能を備えた当社のViewModel内のコマンドがあります

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

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

当社のViewModelにモデルを使用します。 CanExecuteは、モデル内のプロパティまたはChildModel内のプロパティがいつでも再評価されるようにしたいと思います。

これを行う簡単な方法はありますか?

(当社の実際の生産モデルは、他のModelBasesを含む複数の子モデルとリストを持っていることに注意してください)

は現在、私は、すべての子モデル上のすべてのPropertyChangedイベントにフックすることによってそれをやっているが、これはのように思えますこれを行うための汚い方法。

答えて

1

独自の「監視メカニズム」を作成する必要があります。 CatelではChangeNotificationWrapperを使用することができます。

子モデルが更新されるたびに、ViewModelCommandManager.InvalidateCommands(true)を呼び出すことができます。