You will see the words "Hell...">

How can I get TextBlock to literally say "{Binding}"?

In XAML, if you insert

<TextBlock Text="Hello World" />

You will see the words "Hello World".

If you insert

<TextBlock Text="{Binding}" />

it will call the data binding function. But what if I really wanted the displayed text to be "{Binding}"?

Is there an equivalent escape characters in XAML strings?

Or my only solution for this:

<TextBlock>Binding</TextBlock>
+3
source share
4 answers

You can escape the whole line with "{}":

<TextBlock Text="{}{Binding}"/>

Or individual braces can be escaped with a backslash:

<TextBlock Text="{Binding Foo,StringFormat='Hello \{0\}'}" />
+11
source

'{}' - , CDATA:

<TextBlock>
    <TextBlock.Text>
        <![CDATA[{Binding}]]>
    </TextBlock.Text>
</TextBlock>

CDATA .

+6

:

<TextBlock Text="&#123;Binding&#125;" />

.

+1
source

You need to avoid the {and} characters, so you get <TextBlock Text="\{Binding\}" />

0
source

Source: https://habr.com/ru/post/1717044/


All Articles