title: Dynamic menu in WPF
body: <p>How to add menu items to menu control (not contextmenu) in WPF from a database table with Bindings and Observable collections?. I have this menu:</p>
  
  <pre><code>&lt;Menu HorizontalAlignment="Left" Height="27" VerticalAlignment="Top" Width="649"&gt;
      &lt;MenuItem Header="_File"&gt;
         &lt;MenuItem Header="_Exit" Command="{Binding ExitCommand}"/&gt;
         &lt;/MenuItem&gt;
      &lt;MenuItem Header="_MyMenu"&gt;
         &lt;MenuItem Header="_SubMenu1" Command="{Binding  SubMenu1Command}" /&gt;
         &lt;MenuItem Header="_SubMenu2" Command="{Binding  SubMenu2Command}" /&gt;
      &lt;/MenuItem&gt;
  &lt;/Menu&gt;
  </code></pre>
  
  <p>The "SubMenu1" and "_SuMenu2" are values from the database table:</p>
  
  <p>codSubMenu | SubMenuColum | CommandColumn</p>
  
  <p>1_<strong><em>_</em>__<em>_</em>__<em>_</em>__</strong>|<em>SubMenu1</em><strong><em>_</em>__<em>_</em>_</strong>|<em>SubMenu1Command
  2</em><strong><em>_</em>__<em>_</em>__<em>_</em>___</strong>|<em>SubMenu2</em><strong><em>_</em>____</strong>|_SubMenu2Command</p>
  
  <p>I need something this:</p>
  
  <pre><code>&lt;Menu HorizontalAlignment="Left" Height="27" VerticalAlignment="Top" Width="649"
      ItemsSource="{Binding ObservableCollectionMenu}"&gt;
      &lt;MenuItem Header="_File"&gt;
         &lt;MenuItem Header="_Exit" Command="{Binding ExitCommand}"/&gt;
      &lt;/MenuItem&gt;
      &lt;MenuItem Header="_MyMenu"&gt;
          &lt;MenuItem Header="{Binding  ObservableCollectionMenu.SubMenuColumn}" Command="{Binding  ObservableCollectionMenu.CommandColumn}" /&gt;
      &lt;/MenuItem&gt;
  &lt;/Menu&gt;
  </code></pre>
  
  <p>When I run the app the menu must show this when I press the options File and MyMenu:</p>
  
  <p>File | MyMenu</p>
  
  <p>Exit | SubMenu1</p>
  
  <p><em><strong></em>___</strong>| SubMenu2 </p>