如何在 UWP/C# 中使用 svg 文件资源设置 AppBarButton 图标 [英] how to set AppBarButton Icon using svg file resource in UWP/C#
问题描述
Microsoft 文档声明您可以使用 SVG 矢量图形文件设置图标:https://docs.microsoft.com/en-us/windows/uwp/design/style/icons
Microsoft documentation states that you can set icons using SVG vector graphics files: https://docs.microsoft.com/en-us/windows/uwp/design/style/icons
但是,当我尝试使用 svg 文件设置图标时,它只显示空白:
However, when I try to use an svg file to set the icon, it just shows blank:
<AppBarButton Label="BitmapIcon">
<AppBarButton.Icon>
<BitmapIcon UriSource="ms-appx:///Svg/MyButton.svg"/>
</AppBarButton.Icon>
</AppBarButton>
这就是我将 Svg 文件添加到我的项目的方式:在项目下我创建了一个目录Svg",在 Svg 文件夹中我添加了文件MyButton.svg".此 svg 资源文件的属性设置为:
This is how I added Svg file to my project: Under project I created a Directory "Svg", and inside of Svg folder I added the file "MyButton.svg". Property of this svg resource file are set to:
BuildAction:内容
BuildAction: content
复制到输出目录:不要复制
Copy to Output Directory: Do not copy
自定义工具:
自定义工具命名空间:
推荐答案
您不能将 .svg 文件直接用作 AppBarButton
图标.要将 SVG 图标文件加载到 AppBarButton.Icon,您可以将其转换为 PNG、字体或路径,然后使用 FontIcon, BitmapIcon 和 PathIcon 来显示它.更多细节,你可以查看这个类似的线程:
You can not use the .svg file as your AppBarButton
Icon directly. To load the SVG icon file into an AppBarButton.Icon, you can convert it to a PNG, font, or path, then use FontIcon, BitmapIcon and PathIcon to display it. More details, you can look into this similar thread:
这篇关于如何在 UWP/C# 中使用 svg 文件资源设置 AppBarButton 图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!