4
votes

I'm having a little issue here in showing image.

Image is in Assets folder. Here is my XAML code:

<Page
    x:Class="MyApp.WelcomeScreen"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MyApp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"  Width="800" Height="480" RequestedTheme="Dark">

    <Grid Background="#C4043F">
        <Image Name="MyPicture" Source="/Assets/LOGO.png" HorizontalAlignment="Left" VerticalAlignment="Top"/>
   </Grid>
</Page>

I have also tried set source programatically like this and Image is not shown. I have also tried putting try-catch block but exception is not thrown.

string imagePath = "ms-appx:///Assets/LOGO.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imagePath));
MyPicture.Source = bitmapImage;

I have already tried everything that is described here: UWP - Image Uri in Application Folder

What am I missing?

1
Either the relative path is wrong, or the image is not an EmbeddedResource.Herdo
Indeed, if the path to the image is correct, just setting <Image Name="MyPicture" Source="ms-appx:///Assets/LOGO.png" /> should workDepechie
There is deffinitely something wrong with the path. if I add <Image Name="MyPicture" Source="http:// testing-companies.com/wp-content/uploads/2017/03/TEST.png" /> , it works. The Project name in Visual Studio and the folder where the project is saved have different names. Maybe that is what is bothering the Visual Studio...KOmrAD
try Source="ms-appx:///YourProjectName/Assets/LOGO.png"Jet Chopper
it is only item in your grid ? try give height and width for checking purpose. "Check build action is set to content and and try to set always copy to output directory" in image propertiesShubham Sahu

1 Answers

4
votes

Follow this step:

1) Build action is set to content.

2) And try to set always **copy to output directory" in your image properties.

Screenshot