2014-12-27 63 views
0

您好我想實現這樣的結合:MultiBinding ComboBoxItem.Content

<ComboBoxItem Style="{StaticResource ComboBoxItemStyle2}"> 
    <ComboBoxItem.Content> 
     <MultiBinding StringFormat=" {}{0} {1}"> 
      <Binding Path="Value" Source="{StaticResource Name}" /> 
      <Binding Path="Name" Source="{StaticResource Person}" /> 
     </MultiBinding> 
    </ComboBoxItem.Content> 
</ComboBoxItem> 

其中「名稱」是一個本地化的字符串和「價值」是用來獲取它的本地化字符串。 由於某種原因,這似乎並不奏效。我得到空字符串。

回答

1

以下是更正後的代碼:

<ComboBoxItem Style="{StaticResource ComboBoxItemStyle2}"> 
    <TextBlock> 
     <TextBlock.Text> 
      <MultiBinding StringFormat="{}{0} {1}"> 
       <Binding Path="Value" Source="{StaticResource Name}" /> 
       <Binding Path="Name" Source="{StaticResource Person}" /> 
      </MultiBinding> 
     </TextBlock.Text> 
    </TextBlock> 
</ComboBoxItem> 

我需要解決兩件事情:

  1. 保持內容的TextBlock和有文字不具有約束力。
  2. 刪除了StringFormat的額外間距,即「{} {0} {1}」==>「{} {0} {1}」。
1

這可以幫助你:String format using MultiBinding?

從後摘自:

您嘗試將字符串轉換爲綁定目的。但是StringFormat要求它的目標是一個字符串類型。嘗試在你的內容中放置一個TextBlock並將你的數據綁定到它。

也放在名稱周圍。