问题
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 '{0}''}"/>
However, I'm getting XAML parse errors even though I have tried escaping with it with \'
and "
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