2013-02-23 45 views
1

我正在創建一個WPF應用程序。它有兩個使用相同靜態字符串資源的標籤,但有一些差異。例如,它有一個字符串資源,其中的密鑰爲string1,值爲SuccessRate。我希望第一個標籤爲SuccessRate,第二個LabelSuccessRate(%)。我定義與第一標籤:wpf通過字符串操作將屬性設置爲靜態資源

<Label Content="{StaticResource string1}" /> 

我如何定義第二Label

+1

Look [here](http://stackoverflow.com/questions/667511/binding-only-part-of-a-label) – nvoigt 2013-02-23 10:01:02

回答

0

您可以設置第二個標籤的ContentTextBlock有兩個Run元素:

<Label> 
    <TextBlock> 
     <Run Text="{StaticResource string1}"/> 
     <Run Text="(%)"/> 
    </TextBlock> 
</Label> 

也許你需要有唯一的TextBlocks,而不是標籤反正:

<TextBlock Text="{StaticResource string1}"/> 
<TextBlock> 
    <Run Text="{StaticResource string1}"/> 
    <Run Text="(%)"/> 
</TextBlock> 
0

您可以使用ContentStringFormat

<Label Content="{StaticResource string1}" ContentStringFormat="{}{0}(%)" ... /> 

請注意,格式以{}開頭。這只是如果你的格式開始時必須在那裏。 {

你可以在MSDN上閱讀ContentStringFormat