title: Wpf Mvvm ComboBox
body: <p>I am new in the Wpf world, so I created a couple of views and all of them have at least one ComboBox, as I am using the MvvM pattern, I get my self re-typing all the time the same line of codes to fill the Combo and to get the SelectedItem (creating properties, privates for fill and other to get).</p>
  
  <p>Is there some kind of framework that can improve this part ? or hack/trick ??? as I see too much repetitive code... maybe I am doing something wrong, take a look:</p>
  
  <p>XAML:</p>
  
  <pre><code>&lt;ComboBox name= "cbDepartments" DisplayMemberPath="DepartmentName"
                        SelectedValuePath ="PrimaryKey"
                        ItemsSource="{Binding Path=Departments}" 
                        SelectedItem="{Binding Path=DefaultBranch,Mode=TwoWay}" 
  &gt;
  </code></pre>
  
  <p>ViewModel:</p>
  
  <pre><code>private Department defaultBranch;
          public Department DefaultBranch
          {
              get
              {
                  return this.defaultBranch;
              }
  
              set
              {
                  if (this.defaultBranch != value)
                  {
                      this.defaultBranch = value;
                      this.OnPropertyChanged("DefaultBranch");
                      this.saveChangeCommand.RaiseCanExecuteChanged();
                      this.UserMessage = string.Empty;
                  }
              }
          }
  
  private ObservableCollection&lt;Department&gt; departments; 
  public ObservableCollection&lt;Department&gt; Departments
          {
              get { return this.departments; }
              set
              {
                  if (this. departments!= value)
                  {
                      this. departments = value;
                      this.OnPropertyChanged("Departments");
                  }
              }
          }
  </code></pre>