在XAML中使用Apostrophe进行StringFormat绑定不起作用

时间:2014-10-31 11:22:21

标签: wpf xaml silverlight data-binding string-formatting

我在Silverlight 4中工作,我试图在绑定到TextBlock的值中插入撇号:

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

但是,即使我已尝试使用\'&quot;进行转义,但我收到的XAML解析错误仍未成功。

1 个答案:

答案 0 :(得分:7)

这适用于WPF或Silverlight。

<Grid>
    <Grid.Resources>
        <system:String x:Key="Format">The value is '{0}'</system:String>
    </Grid.Resources>

    <TextBlock Text="{Binding MyValue, StringFormat={StaticResource Format}}"/>

</Grid>
相关问题