问题
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