c# - Setting a MenuItem.Icon to an image not working -
I'm dynamically trying to populate a menu in code and setting my icon in C # I am
I have this post read here and the answer given is absolutely right:
My explanation:
MItem.Icon = new image {// filename is just image.png creation output folder source = new bitmap image (new urie (filename, uricind .relevative)}};
But when it comes to run-time, there are no icons. On inspection of data in WPF visualulas, it says that the reality of reality and the actual speed is 0 and it does not appear to be initial (it is to say that the initial and the Islam are loaded).
I bet that I am making a mistake of some kind of cheating but I am not seeing it (for records, every aspect of the menu is working as expected).
>Thank you in advance :) Edit: At the moment, the image is a placeholder for testing only, which I have added as a project link, then 'build action' No 'and' Copy Output Directory 'from' Copy ' And the new image is called "Indicator_off page" and the file name is string on runtime "button indicator_off page"
Edit 2: Also tried:
< Code> var bm = new bitmapImage (); Bm.BeginInit (); Bm.CacheOption = Bitmap option. Download; Bm.UriSource = New Uri (Filename, UriKind.Relative); Bm.EndInit (); MItem.Icon = new image {source = BM};
Setting images to be compiled and used as a resource:
mItem.Icon = new image {source = new bitmapimage (New urri ("pack: // application:. ,,, / buttonIndicator_off.png"))}; I'm almost certain that all these solutions should work so that I think something strange is happening. <3> Edit: Image tested with a rectangular fill: Rectangle_stest image. Fill = new imagebrush (BM);
and it works
After a few attempts, The problem I have successfully tried to do is that you get the cash opsion
to bitmap option. Download is set to
. The important thing is that we have to keep all the initial code between BeginInit ()
and EndInit ()
calls:
var bm = New bitmap image (); Bm.BeginInit (); Bm.CacheOption = Bitmap option. Download; Bm.UriSource = New Uri (Filename, UriKind.Relative); Bm.EndInit (); MItem.Icon = new image {source = BM};
One particular thing is that if you start background
with some ImageBrush
with your BitmapImage
Let's try, we do not need any of the above steps. (Using a controller call passed in Uri).
Also, while embedding your image in the resource
(instead of none
), try this code instead:
mItem.Icon = new Image {source = new bitmapImage (new yuri ("pack: // application: ,,, button /indicator_off.png"))};
Comments
Post a Comment