如何在 UWP/C# 中使用 svg 文件资源设置 AppBarButton 图标 [英] how to set AppBarButton Icon using svg file resource in UWP/C#

查看:25
本文介绍了如何在 UWP/C# 中使用 svg 文件资源设置 AppBarButton 图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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, BitmapIconPathIcon 来显示它.更多细节,你可以查看这个类似的线程:

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:

https://social.msdn.microsoft.com/Forums/en-US/1d32a8b5-a4e1-472b-acce-85c92380b799/uwp-how-to-load-svg-icon-into-appbarbuttonicon?forum=wpdevelop

这篇关于如何在 UWP/C# 中使用 svg 文件资源设置 AppBarButton 图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆