2009-04-25 60 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\}%}"/>