-api-id | -api-type |
---|---|
T:Microsoft.UI.Xaml.Controls.FontIcon |
winrt class |
Represents an icon that uses a glyph from the specified font.
<FontIcon .../>
Use FontIcon
to specify an icon using a Glyph value from a FontFamily. Glyph values are assigned by font developers to private Unicode values that don't map to existing code points.
If you don't specify a FontFamily
, or you specify a FontFamily
that is not available on the system at runtime, the FontIcon
falls back to the default font family defined by the SymbolThemeFontFamily
theme resource.
By default, Windows uses the Segoe Fluent Icon font family. If your app is run on Windows 10, version 20H2 or earlier, the Segoe Fluent Icon font family is not available and the SymbolThemeFontFamily
resource falls back to the Segoe MDL2 Asset font family instead. To use glyphs from the default system font, don't set the FontFamily
property, let it use its default value.
Tip
Many common glyphs from the SymbolThemeFontFamily
are included in the Symbol enumeration. If the glyph you need is available as a Symbol
, you can use a SymbolIcon anywhere you would use a FontIcon
with the default font family.
You can set the MirroredWhenRightToLeft property to have the glyph appear mirrored when the FlowDirection is RightToLeft. You typically use this property when a FontIcon is used to display an icon as part of a control template and the icon needs to be mirrored along with the rest of the control.
If you use a FontIcon
in an AppBarButton, you can set the Foreground
property on the AppBarButton
or on the FontIcon
. If you set the Foreground on the AppBarButton
, it's applied only to the default visual state. It's not applied to the other visual states defined in the AppBarButton
template, like MouseOver
. If you set the Foreground on the FontIcon
, the color is applied to all visual states.
Tip
For more info, design guidance, and code examples, see Command bar.
[!div class="nextstepaction"] Open the WinUI 3 Gallery app and see FontIcon in action
The WinUI 3 Gallery app includes interactive examples of most WinUI 3 controls, features, and functionality. Get the app from the Microsoft Store or get the source code on GitHub.
This example shows an AppBarToggleButton with a FontIcon
.
<AppBarToggleButton Label="FontIcon">
<AppBarToggleButton.Icon>
<FontIcon FontFamily="Segoe UI Emoji" Glyph="▶"/>
</AppBarToggleButton.Icon>
</AppBarToggleButton>
Here's how to create the same button in code.
var newAppBarButton = new AppBarButton();
newAppBarButton.Label = "FontIcon";
var fontIcon = new FontIcon();
fontIcon.FontFamily = new FontFamily("Segoe UI Emoji");
fontIcon.Glyph = "\x25B6";
newAppBarButton.Icon = fontIcon;
using namespace winrt::Windows::UI::Xaml;
...
auto newAppBarButton = Controls::AppBarButton{};
newAppBarButton.Label(L"FontIcon");
auto fontIcon = Controls::FontIcon{};
fontIcon.FontFamily(Media::FontFamily{ L"Segoe UI Emoji" });
fontIcon.Glyph(L"\x25B6");
newAppBarButton.Icon(fontIcon);
IconElement, AppBarButton, SymbolIcon, Icons for Windows apps