Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading