119

I'm trying to do this:

<TextBlock Text="{Binding Path=Text, 
                          Converter={StaticResource stringFormatConverter}, 
                          ConverterParameter='&\u2014{0}'}" />

To get a — to appear in front of the text. It doesn't work. What should I be doing here?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Alex Baranosky
  • 48,865
  • 44
  • 102
  • 150

6 Answers6

233

Since XAML is an XML file format you could try the XML character escape. So instead of writing &\u2014, you could write &#x2014; instead.

ferdley
  • 2,882
  • 2
  • 18
  • 7
11

In xaml I did it like this:

    <Button Grid.Column="1" Grid.RowSpan="2" Name="start" Margin="5" Click="start_Click">
        <TextBlock Name="test" FontFamily="pack://application:,,,/Y_Yoga;Component/Resources/#FontAwesome">&#xF04B;</TextBlock>
    </Button>

Hope to be helpful!

sdd
  • 721
  • 9
  • 23
7

I came to this page for some other reason, but this does not include the easiest and the obvious solution.

This is what I do.

Maintain a static class with all the Unicode values.

 public static class Icons
{
    public const string IconName = "\u2014";
}

And then just bind it wherever you need it.

<TextBlock Text="{x:Static resources:Icons.IconName}" FontFamily="..."/>

This also helps you out with maintenance, all icons would be in one place to manage.

Imran Shaik
  • 305
  • 2
  • 6
3

From Microsoft documentation:

Markup files that are created in Microsoft Visual Studio are automatically saved in the Unicode UTF-8 file format, which means that most special characters, such as accent marks, are encoded correctly. However, there is a set of commonly-used special characters that are handled differently. These special characters follow the World Wide Web Consortium (W3C) XML standard for encoding.

What this means is that you can do zalgo for all you care

enter image description here

Bit of code that is relevant:

<Label Grid.Column="0" Grid.Row="3" FontWeight="ExtraBlack">STAGE:M&#x363;&#x36d;&#x363;&#x33e;  V&#x363;&#x365;&#x36d;&#x35b;&#x364;&#x36e;&#x365;&#x368;&#x365;&#x367;&#x33e;</Label>
Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265
1

Save the file as UTF-8. In Visual Studio, you can do this by going "File" → "Advanced Save Options".

Akku
  • 4,373
  • 4
  • 48
  • 67
0

The UTF-32 syntax in WPF/XAML is like so:   &#x000F1B0A;

<TextBlock Text="foo &#x000F1B0A; bar"
           FontFamily="Material Design Icons" />


enter image description here

This example is using the Material Design Icons desktop font (glyph dump here)

Glenn Slayden
  • 17,543
  • 3
  • 114
  • 108