KOm*_*rAD 4 c# win-universal-app uwp uwp-xaml
我在显示图像时遇到了一个小问题。
图像位于 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>
Run Code Online (Sandbox Code Playgroud)
我也尝试过像这样以编程方式设置源,但图像未显示。我也尝试过放置 try-catch 块,但没有抛出异常。
string imagePath = "ms-appx:///Assets/LOGO.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imagePath));
MyPicture.Source = bitmapImage;
Run Code Online (Sandbox Code Playgroud)
我已经尝试过此处描述的所有内容: UWP - Image Uri in Application Folder
我缺少什么?