Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As others have said the VM shouldn't know about the view directly in MVVM so it doesn't make sense really that the VM triggers something on your custom control to clear everything. </p> <p>I would have set the <code>DataContext</code> of the custom control to an object that has all the properties you want to clear, which are all each bound (two-way) to your textboxes etc. Then in the Save() method you can set a new object (which the custom control <code>DataContext</code> is bound to) and all the properties will be cleared for you (assuming you have implemented <code>INotifyPropertyChanged</code> on the object).</p> <p>UPDATED:</p> <p>As per my comment, see an example of the workaround for your current setup (untested btw):</p> <pre><code> public static DependencyProperty SelectedItemProperty = DependencyProperty.Register("SelectedItem", typeof(CustomObject), typeof(ExampleCustomControl), new PropertyMetadata(default(CustomObject), OnSelectedItemChanged)); private static void OnSelectedItemChanged(DependencyObject source, DependencyPropertyChangedEventArgs e) { var cont = source as ExampleCustomControl; //do all the clearing of txtboxes etc here.... cont.SearchTextBox = string.Empty; } </code></pre> <p>But I would still try and move all this into the VM. i.e. have a clear command, like you do with the save command and bind the textbox text etc to a property in the VM and when the command is called it clears everything, which you can then easily call from the Save method in the VM too. But obviously I have no idea what you are trying to achieve in the long run or how selectedItem and the textboxes etc are related, so depends (as always) i guess.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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