2014-10-31 37 views
3

绑定我在Silverlight 4中工作,我想插入绑定到一个TextBlock值撇号:的StringFormat与撇号XAML不工作

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

但是,我越来越XAML解析错误,尽管我已经尝试使用\'&quot;来逃脱,但没有成功。

回答

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> 
+0

对于那些可能偶然发现这一点的人,因为他们的'StringFormat'不在Tab控件的标题中工作;这不是一个字符串控件。必须将标题的内容分解为一个“TextBlock”,然后使用“StringFormat”。 – OmegaMan 2017-09-14 13:07:12