Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Unicode character as Content of Label in the code-behind?

Tags:

c#

.net

unicode

wpf

I have a Label that looks the following:

<Label Name="FalsePositiveInput" Content="&#x2713;">

This works but how can I do it in the code-behind? I tried this but obviously it's not working:

FalsePositiveInput.Content = "&#x2713;";

The character i want to display is a check mark symbol


2 Answers

Use a unicode escape sequence, rather than a character entity:

FalsePositiveInput.Content = "\u2713";
like image 128
一二三 Avatar answered Sep 13 '25 01:09

一二三


+1 for 一二三

Just one remark: If you want to use extended Unicode, you need to use not \u, but \U and 8 characters, e.g. to display left-pointing magnifying glass (1F50D http://www.fileformat.info/info/unicode/char/1f50d/index.htm) you need to use:

this.MyLabel.Text = "\U0001F50D";

Alternatively as was suggested you can paste right into your source code and then you don't need comments like "//it is a magnifying glass", but then you will have to save your source code in Unicode, which is probably not what you want.

like image 32
Do-do-new Avatar answered Sep 13 '25 01:09

Do-do-new