MicroWither
MicroWither

Reputation: 49

How to change an XAML glyph from C#?

I have an XAML label that shows an empty box. It's using a glyph font-family similar to Microsoft's MDL2 assets (except cross-platform).

<Label Content="&#xE739;" FontFamily="avares://HomeworkCalendar/Assets/Fonts#Symbols" PointerEnter="Check_OnPointerEnter" PointerLeave="Check_OnPointerLeave"/>

When the user hovers over the element I change it from a box to a checkbox.

private void Check_OnPointerEnter(object? sender, PointerEventArgs e) {
    var label = (Label)sender!;
    label.Content = "&#xE73A"; // Checked checkbox
}

private void Check_OnPointerLeave(object? sender, PointerEventArgs e) {
    var label = (Label)sender!;
    label.Content = "&#xE739"; // Unchecked checkbox
}

At program launch it displays the unchecked checkbox but the code-behind changes it to just the text &#xE73A and not a glyph. I know why this is but I can't find anywhere how to parse it differently so it shows up correctly. Anyone know how I can have it parse correctly?

Upvotes: 1

Views: 587

Answers (2)

pshi-ya-chyel
pshi-ya-chyel

Reputation: 151

On my WinUI3 SDK 1.1.0 I used "\uE739" in the *.cs instead of "\xE739" and it works fine.

Upvotes: 0

CyanCoding
CyanCoding

Reputation: 1037

While &#x is used in XAML to denote that the next four characters of a string literal are a hex code, \x is used in C#.

XAML: &#xE739

C#: \xE739

Upvotes: 3

Related Questions