title: Databinding Complex Object Models with WPF
body: <p>I'm currently working on refactoring some old code that was written on top of WPF with C#.</p>
  
  <p>I currently have a composite user model that looks like this:</p>
  
  <pre><code>public class UserModel{
     public User User {get; set;}
     public List&lt;Guid&gt; Permissions {get; set;}
  }
  </code></pre>
  
  <p>In this model the Permissions list is a list of the permission IDs granted to the User referenced by the model.</p>
  
  <p>In my xaml for my user management screen I have a list of these models bound to a combo box and when the selection changes the selected item is bound to a Grid containing text boxes for the User property and an Items Control.</p>
  
  <p>This items control is filled with check boxes bound to all of the permissions in the systems when the page loads. My question is what is the best way to bind the Permissions list to the check boxes in the items control?</p>
  
  <p>The code for the items control looks something like this:</p>
  
  <pre><code>&lt;ScrollViewer Grid.Row="7" Grid.Column="1"&gt;
    &lt;ItemsControl ItemsSource={Binding}&gt;
      &lt;ItemsControl.ItemsTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;Checkbox Content="{Binding Description}" IsChecked="{Binding IsSelected}"/&gt;
          &lt;/DataTemplate&gt;
      &lt;/ItemsControl.ItemsTemplate&gt;
  &lt;/ScrollViewer&gt;
  </code></pre>
  
  <p>And the collection of permissions is a List of this object:</p>
  
  <pre><code>class SelectedPermission{
     public Guid PermissionId {get; set;}
     public string Description {get; set;}
     public bool IsSelected {get; set;}
   }
  </code></pre>
  
  <p>My initial thought was to implement INotifyPropertyChanged on the SelectedPermission collection and when I bind my user just set IsSelected to true for any permissions that are granted to the selected user. But it seems like there should be a better way.</p>