title: WPF MVVM Dynamic ContextMenu
body: <pre><code>&lt;Custom:DataGrid.ContextMenu&gt;
              &lt;ContextMenu ItemsSource="{Binding MenuItemsList, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" /&gt;
  &lt;/Custom:DataGrid.ContextMenu&gt;
  
  public ObservableCollection&lt;MenuItem&gt; MenuItemsList
          {
              get
              {
                       ObservableCollection&lt;MenuItemClass&gt; list = new ObservableCollection&lt;MenuItemClass&gt;();
                  if (SelectedInspection != null)
                  {
                      switch (SelectedInspection.state.s_serverid)
                      {
                          case 1:
                          case 2:
                              list.Add(medit);
                              break;
                          case 3:
                              list.Add(msync);
                              list.Add(mview);
                              list.Add(mnewdoc);
                              break;
                          case 4:
                              list.Add(mview);
                              list.Add(mdelete);
                              break;
                      }
                  }
                 return list;
              }
              set
              {
                  OnPropertyChanged("MenuItemsList");
              }
          }
  </code></pre>
  
  <p>ContextMenu (CM) is in UserControl 1 (UC1).
  Window have 2 usercontrols and main menu to select this controls.</p>
  
  <p>Select UC1 <br/>
  Use CM - OK <br/>
  Select UC2 <br/>
  Select UC1 <br/>
  Use CM - OK</p>
  
  <p><strong>But</strong> <br/>
  Select UC1<br/>
   Use CM - OK <br/>
  Select UC1 <br/>
  Use CM - not update CM Items</p>
  
  <p>I think I should update the view of UC1 when create new viewmodel of UC1, but how?
  Or may be I should rewrite ContextMenu realisation?</p>