在我的 Silverlight 3 应用程序中,我创建了一个自定义工具提示,它会在鼠标悬停在饼图的一部分上时显示。显示的值通过 TemplateBinding 设置:
<ToolTipService.ToolTip>
<StackPanel>
<ContentControl Content="{TemplateBinding IndependentValue}" FontWeight="Bold" />
<ContentControl Content="{TemplateBinding FormattedDependentValue}"/>
<ContentControl Content="{TemplateBinding FormattedRatio}"/>
</StackPanel>
</ToolTipService.ToolTip>
工具提示显示饼图切片的标题、切片大小所基于的值以及整个饼图的百分比:
MyTitel
9
12%
现在,我想向该值添加一个常量字符串,以显示以下内容:
MyTitel
9 items
12%
应将字符串“items”添加到显示的数字中。有没有办法将常量字符串添加到 ContentControl 的 Content-Property? (我对绑定(bind)值 FormattedDependentValue 没有影响)
提前致谢, 弗兰克
最佳答案
不幸的是,Silverlight 没有用于绑定(bind)表达式的 StringFormat 属性。我看到有两种方法可以解决您的问题:
在您的标记中包含一个水平 StackPanel,以添加一个值为“Items”的 TextBlock。这不是您要求的 100%,但它有效。
为绑定(bind)值添加一个转换器。此转换器在 Convert 方法中添加了“Items”常量。顺便说一下,这可以用来实现与 StringFormat 属性等效的东西。参见 Tim Heuer
关于c# - Silverlight 中的 TemplateBinding 和附加字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2454604/