1

I have a WPF contextmenu and I want to add an Item with Icon to this in my C# code. How Can I Do This???

ahmadali shafiee
  • 4,350
  • 12
  • 56
  • 91

2 Answers2

2

There were already questions like this. For example here. So that you wouldn't have to drill down here:

menuItem.Icon = new BitmapImage(new Uri("images/sample.png", UriKind.Relative));
Community
  • 1
  • 1
Nikola Radosavljević
  • 6,871
  • 32
  • 44
1

Should work for you.

<ContextMenu  x:Key="MyContextMenu" >
     <MenuItem  Header="Item1" Click="Ietm1_Click" 
           Icon="{StaticResource ItemIco}" />              

</ContextMenu>

and someone in resources reachable from this cose

<Image x:Key="ItemIco" Source="Images/ItemIco.png"/>

Where Images, natuarally, is a folder of realtive path, in this case.

Tigran
  • 61,654
  • 8
  • 86
  • 123