title: Add Icon from C # code mahapps
body: <p>How can I add an mahapps icon from the code-behind in C#?</p>
  
  <p>In the XAML, according to the doccumentation, it's done like this:</p>
  
  <pre><code>&lt;Rectangle&gt;
    &lt;Rectangle.Fill&gt;
       &lt;VisualBrush Visual="{StaticResource appbar_add}" /&gt;
    &lt;/Rectangle.Fill&gt;
  &lt;/Rectangle&gt;
  </code></pre>
  
  <p>But I have to do it in the code-behind.</p>
  
  <p>Here's what I've tried:</p>
  
  <p><strong>Code-behind</strong></p>
  
  <pre><code>MenuItem item = new MenuItem { Header = menu.Nombre };
  var icono = new VisualBrush() { Visual = (Visual)Resources["appbar_check"] };
  
  if (menu.Submenu != null)
  {
     foreach (var subMenu in menu.Submenu)
     {
        MenuItem subItem = new MenuItem { Header = subMenu.Nombre };
        subItem.Click += Item_Click;
        item.Items.Add(subItem);
     }
  }
  item.Click += Item_Click;
  MenuPrincipal.Items.Add(item);
  </code></pre>
  
  <p><strong>XAML</strong></p>
  
  <pre><code>&lt;Menu Name="MenuPrincipal"&gt;&lt;/Menu&gt;
  </code></pre>