I have this gallery of icons that I downloaded for my UWP project
https://www.nuget.org/packages/FontAwesome.UWP/
I need to Bind the Icon property so the xaml calls it like this:
xmlns:fa="using:FontAwesome.UWP"
and in the grid or in a stackpanel I call it like this:
<StackPanel>
<Viewbox>
<fa:FontAwesome Icon="Industry"/>
</Viewbox>
</StackPanel>
How can I make it bind, I thought that sending a string would work directly but not
For UWP it is a bit different than WPF. In WPF there is the possibility of assigning a binding path that is a string, but in UWP the type is an enum. So one possible solution is to declare the property of the viewmodel that you bind to of type
FontAwesome.UWP.FontAwesomeIcon
.Option 1
And assuming you have the namespace
fa
registered for the nuget ofFontAwesome.UWP
. Something like this:Then you can bind it like this in the view:
Option 2: Using a
IValueConverter
:The other possibility is to pass it a
string
(as you were thinking) and use converter to transform that value to the correct instance ofFontAwesomeIcon
.The first one is easier, as long as you can get the icons you need directly from the enum, but if you need help with this one... let me know :-)
Hope this can help you!
Done, @Karel gave me the idea and I solved it:
First create a class where I will convert the text to icon:
I then add it to a XAML Resource Dictionary:
And now on the page, where I am editing the view, I do this:
And that's it, the Binding is full on the Icon