I need infinity symbol in TextBlock
If I write "∞"
in TextBlock.Text
all good, in TextBlock
"∞" symbol.
<TextBlock Text="∞"/>
But if I use Converter
.
<TextBlock Text="{Binding MyValue, Converter={StaticResource MyConverter}}"/>
I have "∞"
text in TextBlock
.
public class MyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return "∞";
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
Is there any solution?
∞
, aka ∞
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 "∞";
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); //ɢ♠♤ä<>&'"
Console.WriteLine(HtmlEntities.Decode(b)); //ɢ♠♤ä<>&'"
So if you have a string with htmlEntities you can use
return HtmlEntities.Decode("& #8734;");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With