Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So, the ViewModel loads and readies the Models that represent Albums, and the View watches the ViewModel and presents to the users the Albums in a way they can understand.</p> <p>First, let's look at the Model. You have an Album, which has one or more Songs.</p> <pre><code>public sealed class Album { public string Name {get;set;} public string Artist {get;set;} public IEnumerable&lt;Song&gt; Songs {get;set;} } public sealed class Song { public string Name {get;set;} public TimeSpan Length {get;set;} } </code></pre> <p>The ViewModel loads up a public collection of all the Albums</p> <pre><code>public sealed class ViewModel : INotifyPropertyChanged { public ObservableCollection&lt;Album&gt; Albums {get;set;} public Album SelectedAlbum {get;set;} // implement INPC for this property } </code></pre> <p>The ViewModel is the DataContext for the View. Controls bind to Albums and SelectedAlbum. Note, if the ViewModel doesn't have to act on the SelectedAlbum, we could handle the currently selected Album all in the View. This is just an example.</p> <pre><code>&lt;ComboBox ItemsSource="{Binding Albums}" SelectedItem="{Binding SelectedAlbum}" /&gt; </code></pre> <p>Your controls bind relative to SelectedAlbum in order to display information about it</p> <pre><code>&lt;TextBlock Text="{Binding SelectedAlbum.Name}" /&gt; </code></pre> <p>Your DataGrid binds to the Songs property of the SelectedAlbum</p> <pre><code>&lt;DataGrid ItemsSource="{Binding SelectedAlbum.Songs}" /&gt; </code></pre> <p>And everything went better than expected.</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.
 

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