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.

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Sue Maurizio
  • 662
  • 7
  • 17

1 Answers1

7

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>
ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Martin
  • 5,714
  • 2
  • 21
  • 41
  • 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 '17 at 13:07