在XAML绑定的StringFormat无法使用单引号? [英] Can't use apostrophe in StringFormat of a XAML binding?

查看:528
本文介绍了在XAML绑定的StringFormat无法使用单引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的StringFormat插入apostrophies(撇号的?)围绕绑定到一个TextBlock的值:

I'm trying use StringFormat to insert apostrophies (apostrophe's?) around a value that is bound to a TextBlock:

<TextBlock Text="{Binding MyValue, StringFormat='The value is &apos;{0}&apos;'}"/>



不过,我得到一个编译错误:

However, I get a compile error:

名称和值不能包含引号。该的MarkupExtension参数myvalue的,的StringFormat ='的值'{0}''}是无效的。

Names and Values in a MarkupExtension cannot contain quotes. The MarkupExtension arguments ' MyValue, StringFormat='The value is '{0}''}' are not valid.

我做的通知它确实的报价工作,但:

I do notice that it does work for quotes though:

<TextBlock Text="{Binding MyValue, StringFormat='The value is &quot;{0}&quot;'}"/>

这是用的StringFormat一个错误?

Is this a bug with StringFormat?

推荐答案

我不知道这是否是一个错误,但我测试过这个方法,它的工作原理:

I'm not sure if it's a bug, but I tested this method, and it works:

<TextBlock Text="{Binding MyValue, StringFormat='The value is \'{0}\''}" />



好像中的StringFormat单引号都必须使用 \ ,而不是传统的XML样式&放大器;者;

Seems like single quotes within StringFormat have to be escaped using \ as opposed to the traditional XML style &apos;

这篇关于在XAML绑定的StringFormat无法使用单引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆