WPF setting a MenuItem.Icon in code

ScottG picture ScottG · Aug 27, 2008 · Viewed 54.8k times · Source

I have an images folder with a png in it. I would like to set a MenuItem's icon to that png. How do I write this in procedural code?

Answer

Timothy Fries picture Timothy Fries · Aug 27, 2008
menutItem.Icon = new System.Windows.Controls.Image 
       { 
           Source = new BitmapImage(new Uri("images/sample.png", UriKind.Relative)) 
       };