Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Segoe UI Symbols - Programmatically

EDIT:

Below is the format of my XML. It contains data for my IconSheet. I just put only one icon Hex Value for sample.

<Item>
  <ItemInfo>
    <Value>uE101</Value>
    <Name>1</Name>
  </ItemInfo>
</Item>

Here is a snippet from my Code

private void OnLoaded(object sender, RoutedEventArgs e)
    {
        data = (from query in XElement.Load("Data.xml").Descendants("ItemInfo")
                select new ItemInfo
                {
                    value = (int)(query.Element("Value").Value),
                    name = (string)query.Element("Name")
                }).ToList();
        int itemcount = data.length;
        while (itemcount-- > 0)
        {
            TextBlock t = new TextBlock()
            {
                Width = 75,
                Height = 75,
                Text = @"\" + data[itemcount].value,
                FontFamily = new FontFamily("Segoe UI Symbol")
            };
            wrapPanel.Children.Add(t);

        }
    }

in the Snippet Above data[itemcount].value contains data as "uE101". This does not work.

Below code works.

Text = "\uE101"

Any Help would be greatly appreciated.

UPDATE:

With Help from har07 and mishan comments i now have a clear cut idea as to how to handle HEX codes in C#. Thanks for the help. But i Updated the Question what I am trying with and this is what is causing the problem for me.

like image 402
Vamshi Krishna Avatar asked Jul 02 '26 13:07

Vamshi Krishna


1 Answers

You can't separate backslash from next characters in this case. This code :

@"\" + "uE101"

is equal to this :

"\\uE101"

which will output this string instead of special character :

\uE101

They need to be written as single string expression :

"\uE101"

UPDATE :

You can either go with @mishan's second solution by storing only hexadecimal part of the character in xml (<Value>E101</Value>), then parse it to int -> convert int to char -> convert char back to string (following is the example to clarify what I mean) :

.....
TextBlock t = new TextBlock()
            {
                Width = 75,
                Height = 75,
                Text = ((char)int.Parse(data[itemcount].value, NumberStyles.HexNumber)).ToString(),
                FontFamily = new FontFamily("Segoe UI Symbol")
            };
.....

Or to write the exact character to xml and specify xml encoding to a format that support your special characters. You didn't show the codes to create that xml, so I can't help with exact sample that close to yours. But you can search for this topic by keyword "c# write xml document with specific encoding" and will find many examples.

like image 191
har07 Avatar answered Jul 05 '26 04:07

har07



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!