Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to bubble up changes in my ViewModel hierarchy?
    text
    copied!<p>My MainView.xaml contains my SmartForm View:</p> <pre><code>&lt;Grid Margin="10"&gt; &lt;views:SmartForm/&gt; &lt;/Grid&gt; </code></pre> <p>the SmartForm view loads an ItemsControl</p> <pre><code>&lt;Grid Margin="10"&gt; &lt;ItemsControl ItemsSource="{Binding DataTypeViews}"/&gt; &lt;/Grid&gt; </code></pre> <p>which is an ObservableCollection of DataTypeViews:</p> <pre><code>List&lt;FormField&gt; formFields = new List&lt;FormField&gt;(); formFields.Add(new FormField { IdCode = "firstName", Label = "First Name", Value = "Jim" }); formFields.Add(new FormField { IdCode = "lastName", Label = "Last Name", Value = "Smith" }); formFields.Add(new FormField { IdCode = "address1", Label = "Address 1", Value = "123 North Ashton Rd." }); formFields.Add(new FormField { IdCode = "address2", Label = "Address 2", Value = "Box 23434" }); formFields.Add(new FormField { IdCode = "city", Label = "City", Value = "New Haven" }); formFields.Add(new FormField { IdCode = "state", Label = "State", Value = "NM" }); formFields.Add(new FormField { IdCode = "zip", Label = "Zip Code", Value = "34234" }); foreach (FormField formField in formFields) { DataTypeView dtv = new DataTypeView(); DataTypeViewModel dtvm = new DataTypeViewModel(formField); dtv.DataContext = dtvm; DataTypeViews.Add(dtv); } </code></pre> <p>and each view shows the label and textbox which builds a form:</p> <pre><code>&lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="90"/&gt; &lt;ColumnDefinition Width="400"/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;StackPanel Orientation="Horizontal" Grid.Column="0"&gt; &lt;TextBlock Text="{Binding Label}" FontSize="14"/&gt; &lt;TextBlock Text=": " FontSize="14"/&gt; &lt;/StackPanel&gt; &lt;TextBox Grid.Column="1" Text="{Binding Value}" FontSize="12"/&gt; &lt;/Grid&gt; </code></pre> <p>How do I bubble the Textbox changes that happen in DataTypeViewModel up into SmartFormViewModel?</p> <p>Or in other words: <strong>If ViewModel A contains a collection of ViewModel B, and a change happens in a ViewModel B, how can I bubble that change up to ViewModel A?</strong></p>
 

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