Nithin Kamble
Nithin Kamble

Reputation: 55

How to set icon for context menu in c#?

I am trying to set icons for context menu (one which appears when right click is pressed). I'm doing this in a Visual Studio Extensibility project. I used the below code:

MenuItem disConMenuItem = new MenuItem() 
{ Header = "Disconnect", CommandParameter = ClickedTreeViewItem.Header.ToString(), IsEnabled = false, Icon = new System.Windows.Controls.Image 
{ Source = new BitmapImage(new Uri(@".\Icons\disconnect.png", UriKind.Relative)) } };

However the icons appeared while debugging, but not when I install the VSIX. I've also set "Include in VSIX" property of the icon files as 'true'.

Upvotes: 0

Views: 759

Answers (1)

noelicus
noelicus

Reputation: 15055

You want your images to be inside resources, not referenced externally. You could, for example, add a new resource file by r-clicking project and clicking Add -> Add New Item and selecting Resource File and call it myRes. In there you want to add a new image, which you can reference by simply going: myRes.myImage.

Upvotes: 1

Related Questions