Closed kcrg closed 1 year ago
Hey Kacper, thanks a lot for creating this issue, it's interesting.
What is the advantage of using a ResourceDictionary
?
With a ResourceDictionary
, how do you reference the keys (PersonIcon
)? Can you show an example please?
Thanks!
Hi @andreinitescu!
You just need to add this single file FontIcons.xaml ResourceDictionary (without codebehind, I think with codebehind this can work too but this time I create this that way) to MergedDictionaries in App.xaml.
And then just reference keys like any other StaticResource:
Thanks! My question was, why do you prefer using a ResourceDictionary
instead of just using static
class, like this:
<Glyph="{x:Static myApp:IconFont.IconAlarm}"
I mean, is it just a matter of preference? Or does using a ResourceDictionary
have some advantages in some way? (just an example, with a static class
, Visual Studio still provide auto complete like in your screen shot).
The only advantage I can think of is, with resources, you could dynamically switch them at runtime. Like, the app wants to be able to dynamically replace icons at run-time, like an editor app. In this scenario a resource helps a lot, but you would have to use DynamicResource
and not a StaticResource
.
It's just a matter of preference, I think it's a little cleaner to use StaticResource.
@kcrg ✅ DONE! Take it for a spin please 🎉🎈 Let me know what you think, and thanks for taking the time to open the issue.
A little observation: A ResourceDictionary
is actually a Dictionary
, therefore for every entry you put in XAML there's a call at runtime to add the key and value to the dictionary.
So I think it would be better not put 1,000 entries in the XAML for all the icons in the font. Instead, click on the glyphs you need in the app, and the tool will generate the code only for those.
@andreinitescu It looks like everything is working great, thanks for your time
Something like that: