Trying to bind to a BitmapImage created with a Uri pointing to an embedded resource
Posted: 14 May 2019, 19:56
I have a folder called "Images" which contains an embedded resource "MyImage.png".
I can display that image without any issues if I do it like this
But, I can't load the image using a Uri from code-behind... I can see that FileTextureProvider::OpenStream(string path) is returning null.
Is there a way to do this?
I can display that image without any issues if I do it like this
Code: Select all
<Image Source="Images/MyImage.png"></Image>
Code: Select all
<Image Source="{Binding MyImage}"></Image>
public MainWindow()
{
DataContext = this;
BitmapImage test = new BitmapImage(new Uri("Images/MyImage.png", UriKind.Relative));
test.Freeze();
MyImage = test;
}
BitmapSource _myImage;
BitmapSource MyImage
{
get
{
return _myImage;
}
set
{
_myImage = value;
OnPropertyChanged("MyImage");
}
}
Is there a way to do this?