Note that there are some explanatory texts on larger screens.

plurals
  1. POCall RaisedPropertyChanged for Parent Class when Child Property Changes
    primarykey
    data
    text
    <h1>Structure of Program</h1> <p>Currently I am using the MVVMLight 4.1 framework in my application.</p> <p>I have a view model <code>XViewModel</code> which wraps around an instance of <code>XClass</code>, <code>X</code>. <code>X</code> contains many properties such as <code>S</code>. I also have another instance of <code>XClass</code> in another ViewModel.</p> <h3>ViewModel</h3> <pre><code>public XViewModelClass XViewModel : ViewModelBase { public XClass X { get { return x; set } if(value == x) { return; } var oldValue = x; x = value; RaisePropertyChanged(XPropertyName, oldValue, x, true) } } private XClass x; public const string XPropertyName = "X" } </code></pre> <h2>ViewModel2</h2> <pre><code>public YViewModelClass YViewModel : ViewModelBase { public YViewModel() { Messenger.Default.Register&lt;PropertyChangedMessage&lt;XClass&gt;&gt;(this, message =&gt; { X2 = message.NewValue }); } public XClass X2 { get { return x2 set } if(value == x2) { return; } var oldValue = x2 x2= value; RaisePropertyChanged(X2PropertyName) } } private string x2; public const string XPropertyName = "X2" } </code></pre> <h2>Model</h2> <pre><code>public class X : ObservableObject { public string S { get { return s; set } if(value == S) { return; } s = value; RaisePropertyChanged(SPropertyName) } } private string s; public const string XPropertyName = "S" } </code></pre> <h1>Problem</h1> <p>How do I ensure that when any property in <code>X</code> changes (e.g. <code>S</code> is set to a different value), <code>RaisePropertyChanged</code> is called for <code>X</code>. It would be best if I don't have to send a property changed message for every property in my model.</p> <p>The reason behind is that I have another instance of <code>XClass</code>, `X2' in another ViewModel and I want to keep both instances in sync.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload