StringFormat Binding with Apostrophe in XAML Not Working

走远了吗. 提交于 2019-12-10 17:46:22

问题


I'm working in Silverlight 4 and I'm trying to insert an apostrophe in a value that is bound to a TextBlock:

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

However, I'm getting XAML parse errors even though I have tried escaping with it with \' and &quot; to no success.


回答1:


This will work in WPF or 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>


来源:https://stackoverflow.com/questions/26673509/stringformat-binding-with-apostrophe-in-xaml-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!