我在显示图片方面遇到了一点问题。
图片在Assets文件夹中。 这是我的XAML代码:
<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>
我也尝试过像这样通过编程设置源,但图片没有显示。我还尝试了使用try-catch块,但异常未被抛出。
string imagePath = "ms-appx:///Assets/LOGO.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imagePath));
MyPicture.Source = bitmapImage;
我已经尝试了这里描述的所有方法:UWP - 应用文件夹中的图像Uri。我还缺少什么?
Source="ms-appx:///YourProjectName/Assets/LOGO.png"
- Jet Chopper