charri / Font-Awesome-WPF

FontAwesome controls for WPF+UWP
MIT License
533 stars 145 forks source link

Get Icon By ID #22

Open addftoxic opened 8 years ago

addftoxic commented 8 years ago

Would it be possible to generate a function that receives string representing the ID of the icon, as can be found on https://fortawesome.github.io/Font-Awesome/icons/ , and returns the enum that can be bound in a fa:ImageAwesome tag? If the string does not match with any valid icon, I'd imagine the function returning 'question', though maybe a second parameter could accept the preferred "error" icon, in the form of the enum.

charri commented 8 years ago

currently the id is only used during the FontAwesomeIcon enum generation process to build the cref url for xmldoc. I personally would create a converter to convert the string to an enum to bind to an fa:ImageElement, just need to add the Id as an attribute (get by reflection) or a static lookup dictionary generated the same time as the FontAwesomeIcon

Its certainly something I would be willing to look into :)

charri commented 8 years ago

There is now an example on how to do this (release 4.5.0.7).

addftoxic commented 8 years ago

Thanks - that's awesome. But it doesn't work for all icons. From what I can tell, it seems to be coughing up on icons with aliases. For example: umbrella, book, wrench, search, and check-square-o all work; but exclamation-triangle (AKA warning), users (AKA group), and clipboard (AKA paste) all show FontAwesomeIcon.None using FromStringToIcon and null using FromIconToString.

charri commented 8 years ago

Aliases will not work - as they have the same value as that of a normal icon, i wouldn't be able to create a two-way binding.

I will have a look at the icons with aliases - must be doing something wrong - grr

thanks for reporting :+1:

addftoxic commented 7 years ago

I was doing some testing with this again and I discovered that "exclamation-triangle" and "users" were both working for me, and I'm not sure when this changed. The icons "clipboard" and "bolt" were still showing as boxes. These both have aliases, but I don't know what's different here than the other 2 that are working. I went into the example project to see if these worked there, but could not even find them in the list.