UWP 应用程序不显示图像 [英] UWP App does not show Image
本文介绍了UWP 应用程序不显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在显示图片时遇到了一个小问题.
图像位于 Assets 文件夹中.这是我的 XAML 代码:
<网格背景="#C4043F"><Image Name="MyPicture" Source="/Assets/LOGO.png" HorizontalAlignment="Left" VerticalAlignment="Top"/></网格></页面>
我也试过像这样以编程方式设置源代码,但没有显示图像.我也试过放置 try-catch 块,但没有抛出异常.
string imagePath = "ms-appx:///Assets/LOGO.png";BitmapImage bitmapImage = new BitmapImage(new Uri(imagePath));MyPicture.Source = bitmapImage;
我已经尝试了这里描述的所有内容:
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?
解决方案
Follow this step:
1) Build action is set to content.
2) And try to set always **copy to output directory" in your image properties.
这篇关于UWP 应用程序不显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文