UWP App does not show Image

陌路散爱 提交于 2020-01-14 14:41:07

问题


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:


Follow this step:

1) Build action is set to content.

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



来源:https://stackoverflow.com/questions/47095187/uwp-app-does-not-show-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!