title: Why does my context menu look different when generated dynamically
body: <p>I am trying to dynamically bind context menus from my base view model.  I've managed to functionally do what i'd like to do, but I'm stuck with how my dynamic context menu looks compared to my static one.  There seems to be an extra level of menu items.  My View Model looks like this.</p>
  
  <pre><code> public ObservableCollection&lt;ContextMenuItem&gt; ContextMenuItems { get; protected set; }
  
  protected Constructor 
  {
       ContextMenuItems = new ObservableCollection&lt;ContextMenuItem&gt;()
                      {
                          new ContextMenuItem() {Caption = "Add/Replace Supporting Data", Command = AddReplaceSupportingCommand},
                          new ContextMenuItem() {Caption = "Display SupportingData", Command = DisplaySupportingDataCommand}
                      };
  }
  </code></pre>
  
  <p>the xaml for the 1st context menu us generated like this.</p>
  
  <pre><code>    &lt;StackPanel Orientation="Vertical" Margin="0,20"&gt;
              &lt;StackPanel.ContextMenu &gt;
                  &lt;ContextMenu ItemsSource="{Binding ContextMenuItems}"&gt;
                      &lt;ContextMenu.ItemTemplate&gt;
                          &lt;DataTemplate&gt;
                              &lt;MenuItem Command="{Binding Command}" Header="{Binding Caption}"/&gt;
                          &lt;/DataTemplate&gt;
                      &lt;/ContextMenu.ItemTemplate&gt;
                  &lt;/ContextMenu&gt;
              &lt;/StackPanel.ContextMenu&gt;
  ...
  
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>The xaml for the second context menu looks like this</p>
  
  <pre><code>&lt;StackPanel &gt;
          &lt;StackPanel.ContextMenu&gt;
              &lt;ContextMenu&gt;
                  &lt;MenuItem Command="{Binding AddReplaceSupportingCommand}" Header="Add or Replace Supporting Data"/&gt;
                  &lt;MenuItem Command="{Binding DisplaySupportingDataCommand}" Header="Display Supporting Data"/&gt;
              &lt;/ContextMenu&gt;
          &lt;/StackPanel.ContextMenu&gt;
  ...
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>(for completeness, here's the ContextMenuItem class) </p>
  
  <pre><code>public class ContextMenuItem : ReactiveObject
      {
          private string _Caption;
          public string Caption
          {
              get { return _Caption; }
              set { this.RaiseAndSetIfChanged(ref _Caption, value); }
          }
  
          public ReactiveCommand Command { get; set; }
      }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/5h7yU.jpg" alt="Differences between dynamic and statically generated context menus"></p>