2009-04-25 183 views

回答

65

还有就是,如果你是对的.Net 3.5 SP1

<TextBlock Text="{Binding Path=Artist.Fans.Count, 
       StringFormat='Number of Fans: {0}'}" /> 
+1

是否可以使用多个输出,类似于string.Format([1],[2],[3],... [n])中的args []? – 2016-07-12 07:06:56

+1

它缺少转义\ {0 \} – 2017-11-28 20:07:44

3

使用Binding.StringFormat

<TextBlock Text="{Binding Artist.Fans.Count, StringFormat='Number of Fans: {0}'}"/> 
+0

您好Danko - 你知道如何使它与属性元素语法工作? – BKSpurgeon 2017-07-17 07:43:26

24

在使用上述办法:

<TextBlock Text="{Binding Path="Artist.Fans.Count", 
        StringFormat='Number of Fans: {0}'}" /> 

我发现它在一定程度上限制我不能找到一种方法,大胆的面对内部的StringFormat和我可能会在使用的StringFormat撇号。

相反,我去这种方法,它更好地工作对我来说:

<TextBlock TextWrapping="Wrap"> 
    <Run>The value</Run> 
    <Run Text="{Binding Path=MyProperty1, Mode=OneWay}" FontWeight="Bold" /> 
    <Run>was invalid. Please enter it with the format... </Run> 
    <LineBreak/><LineBreak/> 
    <Run>Here is another value in the program</Run> 
    <Run Text="{Binding Path=MyProperty2, Mode=OneWay}" FontWeight="Bold" /> 
</TextBlock>      
1

这里的绑定值(clouds.all)加用“%”。您可以在“\ {0 \}”之后添加所需的任何值。

<TextBlock Text="{Binding Path=clouds.all, StringFormat=\{0\}%}"/> 
相关问题