For quite some time, the FontImageExtension has been used to display font icons inside controls. But, as part of the news in .NET 10 for .NET MAUI, this extension is now deprecated, which means you should no longer use it in your projects and start preparing to migrate to the new recommended extension.
But… which one is the recommended extension? 🤔
We now have the FontImageSource markup extension, which allows you to display icons just like the deprecated one, but in a clearer and more consistent way.
Using FontImageSource is very simple, you just need to know the following properties:
➖ Glyph: The symbol of the icon.
➖ Color: The color of the icon.
➖ Size: The size of the icon.
➖ FontFamily: The font that contains the icon (e.g., FontAwesome).
And you have two ways to implement it, as I’ll show you below:
1️⃣ Inline syntax
This is a more direct and compact way, where FontImageSource is defined directly as the value of the ImageSource property. However, keep in mind that if you need to define multiple properties/values, it can become a bit harder to read.
2️⃣ Property element syntax
In this expanded option, instead of setting the value directly in the attribute, you have to open a <Control.ImageSource> block. For example, if you are working with a Button, you can add a <Button.ImageSource> block and place the FontImageSource inside it.
It may look much longer because it requires a more detailed structure, but it’s far more readable, especially when it contains multiple properties.
And that’s it! 🎉 In just a few minutes you know how to react when you see FontImageExtension: simply replace it with FontImageSource! 😎
🙌 Thanks for reading my article!
If you have any questions, feel free to leave them in the comments. 💚💕
See you next time! 🙋♀️
References
This article was based on the official documentation.