Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Infinity symbol in TextBlock

I need infinity symbol in TextBlock

If I write "∞" in TextBlock.Text all good, in TextBlock "∞" symbol.

<TextBlock Text="&#8734;"/> 

But if I use Converter.

<TextBlock Text="{Binding MyValue, Converter={StaticResource MyConverter}}"/> 

I have "&#8734;" text in TextBlock.

 public class MyConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {           
           return "&#8734;";           
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
           throw new NotImplementedException();
        }
    }

Is there any solution?

like image 959
Alexandr Avatar asked Dec 14 '22 20:12

Alexandr


2 Answers

&#8734;, aka &#x221E; is an XML character reference, it is turned into the character U+221E when the XML file containing it is parsed. However outside of XML, in a C# string literal, the &# sequence means nothing special, just an ampersand and hash. String literals in C# use the backslash character for their escapes rather than XML-style character references so to include an infinity sign in an ASCII-safe string literal:

return "\u221E";

Or if your editor and compiler agree on source code encoding, you can say simply:

return "∞";
like image 79
bobince Avatar answered Dec 30 '22 03:12

bobince


I found this topic on stackoverflow: Does C# have something like PHP's mb_convert_encoding()?

string a = "ɢ♠♤ä<>&'\"";
string b = HtmlEntities.Encode(a);
Console.WriteLine(b); //&#610;&spades;&#9828;&auml;<>&'"
Console.WriteLine(HtmlEntities.Decode(b)); //ɢ♠♤ä<>&'"

So if you have a string with htmlEntities you can use

return HtmlEntities.Decode("& #8734;");
like image 38
Revils Avatar answered Dec 30 '22 01:12

Revils