在WPF中,是否有任何方法使TextBlock
的Text
属性包含硬编码文本和特定绑定?使用TextBlock中的绑定对硬编码文本进行编码
我心目中什么是沿着以下线的东西(ofcourse,以下不会编译):
<TextBlock Text="Number of Fans: {Binding Artist.Fans.Count}"></TextBlock>
在WPF中,是否有任何方法使TextBlock
的Text
属性包含硬编码文本和特定绑定?使用TextBlock中的绑定对硬编码文本进行编码
我心目中什么是沿着以下线的东西(ofcourse,以下不会编译):
<TextBlock Text="Number of Fans: {Binding Artist.Fans.Count}"></TextBlock>
还有就是,如果你是对的.Net 3.5 SP1
<TextBlock Text="{Binding Path=Artist.Fans.Count,
StringFormat='Number of Fans: {0}'}" />
<TextBlock Text="{Binding Artist.Fans.Count, StringFormat='Number of Fans: {0}'}"/>
您好Danko - 你知道如何使它与属性元素语法工作? – BKSpurgeon 2017-07-17 07:43:26
在使用上述办法:
<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>
这里的绑定值(clouds.all)加用“%”。您可以在“\ {0 \}”之后添加所需的任何值。
<TextBlock Text="{Binding Path=clouds.all, StringFormat=\{0\}%}"/>
是否可以使用多个输出,类似于string.Format([1],[2],[3],... [n])中的args []? – 2016-07-12 07:06:56
它缺少转义\ {0 \} – 2017-11-28 20:07:44