Add an image

	<Image Source ="Assets/test_image1.png" Stretch="UniformToFill" />
	<Image Source ="Assets/Background.png" Stretch="UniformToFill" HorizontalAlignment="Center" VerticalAlignment="Center" />

	<Image Canvas.Left="380" Canvas.Top="198" Width="40" Height="40" Source="Assets/Icon_Loading.png" x:Name="LoadingIcon"  />

Stretch options:

None – No scaling is done.
Fill – Image will fill the space and aspect ratio is ignored.
Uniform – Show the entire image with blank space in one axis if needed.
UniformToFill – Ensure the whole space is filled and the aspect ration is preserved, cropping if necessary.

Adding image files to the assets folder

You need to right click the Assets folder in Visual Studio and select Add existing item (you can’t just copy files into the folder in explorer)

Image From Local Folder

img.Source = new BitmapImage(new Uri("ms-appdata:///local/SomeFolder/Logo.png"));

Spreading across whole grid

	<Image Source="MyImage.png" Stretch="UniformToFill" Grid.ColumnSpan="999" Grid.RowSpan="999"/>

Changing Image Without Blanking

Preloading the image doesn’t seem to work, the workaround until this gets fixed seems to be to have 2 images, one set to collapsed.  When you want to display a new image set the collapsed visibility one to show it and create a method for its ImageOpened event which makes it visible and collapses the visibility of the other.  Dull, but does the job

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *