资产文件夹中的图像在 UWP 应用程序中不起作用
Images from Assets Folder are not working in UWP app
图像在 MainPage 中工作,但我试图将它集成到导航面板模板中,但图像没有显示。谁能告诉我可能是什么问题。
Templete 正在使用 FRAMES,但这不应该是问题所在。
XAML代码
<Button Grid.Column="0" Style="{StaticResource NavigationButtonStyle}">
<StackPanel Orientation="Horizontal">
<Image Source="Assets/donut-icon.png" Style="{StaticResource IconImageStyle}" />
<TextBlock Text="Donut" Foreground="White" />
</StackPanel>
</Button>
样式资源
<Style TargetType="Image" x:Key="IconImageStyle">
<Setter Property="Height" Value="20" />
<Setter Property="Width" Value="20" />
<Setter Property="Margin" Value="0,0,10,0" />
</Style>
我注意到您的页面在您的 "Pages/Go Nuts" 文件夹中,因此您应该使用以下 URI 来获取图像。
<Image Source="ms-appx:///Assets/donut-icon.png" />
或者
<Image Source="/Assets/donut-icon.png" />
使用<Image Source="Assets/donut-icon.png" />
时,它将在当前文件夹中搜索资源。但是当前文件夹下没有这个资源,所以无法运行。
图像在 MainPage 中工作,但我试图将它集成到导航面板模板中,但图像没有显示。谁能告诉我可能是什么问题。
Templete 正在使用 FRAMES,但这不应该是问题所在。
XAML代码
<Button Grid.Column="0" Style="{StaticResource NavigationButtonStyle}">
<StackPanel Orientation="Horizontal">
<Image Source="Assets/donut-icon.png" Style="{StaticResource IconImageStyle}" />
<TextBlock Text="Donut" Foreground="White" />
</StackPanel>
</Button>
样式资源
<Style TargetType="Image" x:Key="IconImageStyle">
<Setter Property="Height" Value="20" />
<Setter Property="Width" Value="20" />
<Setter Property="Margin" Value="0,0,10,0" />
</Style>
我注意到您的页面在您的 "Pages/Go Nuts" 文件夹中,因此您应该使用以下 URI 来获取图像。
<Image Source="ms-appx:///Assets/donut-icon.png" />
或者
<Image Source="/Assets/donut-icon.png" />
使用<Image Source="Assets/donut-icon.png" />
时,它将在当前文件夹中搜索资源。但是当前文件夹下没有这个资源,所以无法运行。