title: How to add horizontal separator in a dynamically created ContextMenu?
body: <p>I was looking for the solution on the internet but was not able to find it within my sample. I need to add a separator between Context menu item that are generated from code behind. I tried to add it with such code lines like below but without success. </p>
  
  <pre><code>this.Commands.Add(new ToolStripSeparator()); 
  </code></pre>
  
  <p>I am wondering if someone can help. Thank you in advance.</p>
  
  <p>Context Menu XAML:</p>
  
  <pre><code>&lt;Style x:Key="DataGridCellStyle" TargetType="{x:Type DataGridCell}"&gt;
      &lt;Setter Property="ContextMenu"&gt;
          &lt;Setter.Value&gt;
              &lt;ContextMenu ItemsSource="{Binding Commands}"&gt;
                  &lt;ContextMenu.ItemContainerStyle&gt;
                      &lt;Style TargetType="{x:Type MenuItem}"&gt;
                          &lt;Setter Property="Command" Value="{Binding}" /&gt;
                          &lt;Setter Property="Header" Value="{Binding Path=Text}" /&gt;
                          &lt;Setter Property="CommandParameter" Value="{Binding Path=Parameter}" /&gt;
                      &lt;/Style&gt;
                  &lt;/ContextMenu.ItemContainerStyle&gt;
              &lt;/ContextMenu&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  </code></pre>
  
  <p>C# that added in the method:</p>
  
  <pre><code>this.Commands = new ObservableCollection&lt;ICommand&gt;();
          this.Commands.Add(MainWindow.AddRole1);
          this.Commands.Add(MainWindow.AddRole2);
          this.Commands.Add(MainWindow.AddRole3);
          this.Commands.Add(MainWindow.AddRole4);
          //this.Add(new ToolStripSeparator()); 
          this.Commands.Add(MainWindow.AddRole5);
          this.Commands.Add(MainWindow.AddRole6);
          this.Commands.Add(MainWindow.AddRole7); 
  </code></pre>