Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set AppBarButton Icon using svg file resource in UWP/C#

Tags:

c#

xaml

uwp

Microsoft documentation states that you can set icons using SVG vector graphics files: https://docs.microsoft.com/en-us/windows/uwp/design/style/icons

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>

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: content

Copy to Output Directory: Do not copy

Custom Tool:

Custom Tool Namespace:

like image 540
Bimo Avatar asked May 22 '18 00:05

Bimo


People also ask

How do I add an SVG icon?

SVG images can be written directly into the HTML document using the <svg> </svg> tag. To do this, open the SVG image in VS code or your preferred IDE, copy the code, and paste it inside the <body> element in your HTML document. If you did everything correctly, your webpage should look exactly like the demo below.

How do I save icon as SVG?

Export Settings From within Adobe Illustrator select File ⇨ Save As. When the 'Save As' window appears, give your icon a name and change the 'Format' option at the bottom to SVG (svg). Give your icon a descriptive name and set the format as SVG.


1 Answers

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

like image 117
Breeze Liu - MSFT Avatar answered Sep 20 '22 15:09

Breeze Liu - MSFT