Try something like this:
this.xml_menuItem_001.Icon = new Image { Source = new BitmapImage( new Uri( @"c:\1\WPF10\media-floppy-5.png" ) ) };
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I have XAML file and a menuitem in it (in a classic menu):
<MenuItem Name="xml_menuItem_001" Header="_Manage users" />
I would like to load an icon for this menuitem from a file which is placed to:
c:\1\WPF10\media-floppy-5.png
using code-behind. If it possible ?
I am trying this code, but without any success:
this.xml_menuItem_001.Icon = BitmapFrame.Create(
Application.GetResourceStream(
new Uri(@"c:\1\WPF10\media-floppy-5.png")).Stream);
Is there a suitable way to load the icon from file at running time using code behind ? :)
Jerry
PS: I really like Microsoft, suitable manual is everywhere and it is not necessary for a men to beg for an advice on public forums :) :) :) :) ha ha ha
I am permanently happy ...
Try something like this:
this.xml_menuItem_001.Icon = new Image { Source = new BitmapImage( new Uri( @"c:\1\WPF10\media-floppy-5.png" ) ) };
In one place of my app I've done it this way:
var image = new Image() {
Margin = new Thickness(0, 10, 0, 0),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top,
Width = 96,
Height = 96,
};
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("RentManager.Resources.LoadingIcon.png")){
image.Source = BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
}
and it works.
wou it is working ok, thanks :)