Difference between image URI behavior in code and in XAML

I have an image declared in some XAML as:

<Image Width="188" Height="56" HorizontalAlignment="Left"  VerticalAlignment="Bottom" Margin="10,0,0,10" Grid.ColumnSpan="2" Grid.Column="0" Source="..\Images\myImage.png" />

This is a static image and does not need to be changed at runtime.

I also have an image that needs to be changed at runtime, depending on the set of values.

I use iValueConverter to convert data to images that seem to work, but I am having problems creating the images themselves.

I am trying to create a series of objects System.Windows.Media.Imaging.BitmapImagefor storing images. As in the code above, I am trying to access the .PNG stored in the \ Images directory:

Dim ThisImage As New BitmapImage(New Uri("..\Images\thisImage.png", UriKind.Relative))

While using `` .. \ Images \ "works fine for XAML, opening the image stored in [Project Directory] \ Images \ correctly in code that seems to go to [Project Directory] \ bin \ Images \ which does not exist.

Obviously, I'm screwing something, but I do not want to start trying to go directly to the file, since it obviously will not be in the same place after installing it ...

What am I missing here? Why doesn't the XAML URI work the same as the code URI?

+3
source share
2 answers

Image.Source XAML URI, (ImageSourceConverter) URI ImageSource. IUriContext XAML, URI URI.

BitmapImage, BitmapImage URI, , URI. URI, "pack://application:,,,/Images/thisImage.png"

+3

, , Uri, .

, XAML, ImageSourceConverter ( Uri xaml ImageSource) Uris Uris IUriContext, ITypeDescriptorContext. , . ( - xaml), Uri xaml ImageSource.

+1

Source: https://habr.com/ru/post/1767156/


All Articles