2010-03-16 53 views
3

在我的Silverlight 3應用程序中,我創建了一個自定義的Tooltip,當鼠標懸停在Pie-Chart的一部分上時顯示。顯示的值是通過TemplateBinding設置:Silverlight中的TemplateBinding和附加字符串

<ToolTipService.ToolTip> 
    <StackPanel> 
    <ContentControl Content="{TemplateBinding IndependentValue}" FontWeight="Bold" /> 
    <ContentControl Content="{TemplateBinding FormattedDependentValue}"/> 
    <ContentControl Content="{TemplateBinding FormattedRatio}"/> 
    </StackPanel> 
</ToolTipService.ToolTip> 

工具提示顯示扇形區的標題,值片的大小是根據與有關整個餅的百分比:

MyTitel

12%

現在,我想一個常量字符串添加到值,顯示如下:

MyTitel

9項

12%

字符串 '項目' 應被添加到顯示的號碼。有沒有辦法將常量字符串添加到ContentControl的Content-Property? (我有綁定的值FormattedDependentValue沒有影響)

由於提前, 弗蘭克

回答

2

不幸的是,Silverlight不具有綁定表達式的屬性的StringFormat。我看到兩種方法來解決你的問題:

  1. 在你的標記中包含一個水平的StackPanel來添加一個TextBlock值'Items'。這不是你要求的100%,但它的工作原理。

  2. 將轉換器添加到綁定值。該轉換器在Convert方法中添加了'Items'常量。這可以用來實現與StringFormat屬性等同的東西。見Tim Heuer

+0

我已經通過添加StackPanel解決了它。非常感謝! – Aaginor 2010-03-22 14:55:47