Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What we have been doing is wrapping the Model lists within an ObservableCollection. This ObservableCollection is usually also a ViewModel for the Child object, so we can control its view and be able to pass the ViewModel to another view when necessary. You will have two lists, but they will contain the same object references. It may seem like a duplication of effort, but with a decent use of Inheritance, you can still maintain a DRY approach. Remember the idea of MVVM is to create an Abstraction between your View and the Model, it may seem like you are saving yourself the effort upfront by not wrapping the Child objects, however we have found that there is almost always a need to tranform these Child objects later.</p> <pre><code>public class DealerViewModel : ViewBase { // This concept can be wrapped in a ListViewBase for a more DRY approach private ObservableCollection&lt;CarViewModel&gt; cars; public ObservableCollection&lt;CarViewModel&gt; Cars { get { return cars; } set { if (cars == value) return; cars = value; RaisePropertyChanged("Cars"); } } // This concept can be wrapped in a ListViewBase for a more DRY approach private CarViewModel selectedCar; public CarViewModel SelectedCar { get { return selectedCar; } set { if (selectedCar== value) return; selectedCar= value; RaisePropertyChanged("SelectedCar"); } } public DealerViewModel(Dealer dealer) { // This concept can be wrapped in a ListViewBase for a more DRY approach Cars = new ObservableCollection(dealer.Cars.Select(c =&gt; new CarViewModel(c))); } } public class CarViewModel { } </code></pre>
 

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