I am trying to load a image from Embedded Resource to an Image instance. The problem is the size of the image is always 0.
Here is the code snippet:
Image image = new Image();
ImageSource img = new System.Windows.Media.Imaging.BitmapImage(new Uri("/Images/marker.png", UriKind.Relative));
image.SetValue(Image.SourceProperty, img);
System.Diagnostics.Debug.WriteLine("output 1 = " + image.DesiredSize.Width); // return 0
System.Diagnostics.Debug.WriteLine("output 2 = " + image.ActualWidth); // return 0
I have to know the size of the image before it rendered on the screen, because I need to offset the image depending on the size of it.
Thank you
Update:
Thanks Silvermind
I answered my own question with sample code
Thanks Silvermind. He suggested to use CreateOptions.
Finally, I found a solution: