3

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 Answer 1

7
+50

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>
1
  • For those who may stumble upon this because their StringFormat is not working in a Tab control's header; that is not a string control. One has to break out the header's content into a TextBlock and then use the StringFormat.
    – ΩmegaMan
    Sep 14, 2017 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.