how to use MenuItem in another MenuItem in wpf <p>I want to make a menu like this in wpf</p> <p><img src="https://i.stack.imgur.com/BeCm5.jpg" alt="enter image description here"></p> <p>I wrote this code:</p> <pre><code>&lt;MenuItem Header="Menu 4" MouseEnter="mousecom" Background="DarkGreen"&gt; &lt;MenuItem.ContextMenu&gt; &lt;ContextMenu&gt; &lt;MenuItem Header="submenu 1"/&gt; &lt;MenuItem Header="submenu 2"/&gt; &lt;/ContextMenu&gt; &lt;/MenuItem.ContextMenu&gt; &lt;/MenuItem&gt; </code></pre> <p>and <code>mousecom</code> is:</p> <pre><code>private void mousecom(object sender, MouseEventArgs e) { while (IsMouseOver) { (sender as Button).ContextMenu.IsEnabled = true; (sender as Button).ContextMenu.PlacementTarget = (sender as Button); (sender as Button).ContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Right; (sender as Button).ContextMenu.IsOpen = true; } } </code></pre> <p>I mean I wanna have a MenuItem and by coming mouse on it another menu opens including some other MenuItems.</p> <p>Why it doesn't work?</p> <p>how can I do that? (please pay attention to the picture)</p>