And*_*erd 3 data-binding wpf xaml text textblock
在XAML中,如果插入
<TextBlock Text="Hello World" />
Run Code Online (Sandbox Code Playgroud)
你会看到"Hello World"这个词.
如果你插入
<TextBlock Text="{Binding}" />
Run Code Online (Sandbox Code Playgroud)
它将触发数据绑定功能.但是如果我真的希望显示文字是"{Binding}"呢?"
XAML字符串中是否存在等效的转义字符?
或者是我唯一的解决方案:
<TextBlock>Binding</TextBlock>
Run Code Online (Sandbox Code Playgroud)
Mat*_*ton 11
您可以使用"{}"转义整个字符串:
<TextBlock Text="{}{Binding}"/>
Run Code Online (Sandbox Code Playgroud)
或者可以使用反斜杠转义单个花括号:
<TextBlock Text="{Binding Foo,StringFormat='Hello \{0\}'}" />
Run Code Online (Sandbox Code Playgroud)
根据Matt的响应使用'{}'进行转义是要走的路,但为了完整起见,您还可以使用CDATA部分:
<TextBlock>
<TextBlock.Text>
<![CDATA[{Binding}]]>
</TextBlock.Text>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)
CDATA部分对多行文本更有用.