2012-08-09 49 views
16

我有一個問題,運行的綁定不起作用。 這是我目前的代碼。XAML TextBlock和運行綁定

<TextBlock 
    x:Name="txtCompanyName" 
    Text="{Binding Path=SelectedItem.CompanyName, ElementName=lbSourceList}" 
    Foreground="White" 
    FontSize="18.667" 
    Height="33.667" 
    Margin="10,-0.5,0,-1.5"> 
    <Run Text=" : " Foreground="White"/> 
    <Run Text=" "/> 
    <Run Text=" " Foreground="White"/> 
    <Run Text=" "/> 
    <Run Text="{Binding Path=SelectedItem.RFQID, ElementName=lbSourceList}" /> 
</TextBlock> 

我得到的公司名稱出現,但額外的數據永遠不會出現。 任何想法爲什麼這種類型的綁定失敗?


備選答案連同最後的答案

<TextBlock TextWrapping="Wrap" 
      Text="{Binding RFQID}" 
      FontWeight="Bold" 
      Foreground="#FFFFF504" 
      HorizontalAlignment="Left" Width="185"> 
      <Run Text=" ~ "/> 
      <Run Text="{Binding RFQNo}" FontWeight="Bold" Foreground="#FFFFF504"/> 
      <Run Text=" ~ "/> 
      <Run Text="{Binding Status}" FontWeight="Bold" 
             Foreground="#FF85F35F"/> 
</TextBlock> 
+0

顯示你的[裝訂錯誤](http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/30/debugging-data-bindings-in-a-wpf-or-silverlight-application。 aspx)... – 2012-08-09 11:11:21

+0

謝謝。沒有顯示任何綁定錯誤 – scottsanpedro 2012-08-09 11:21:05

+0

自WPF 4.0開始,您可以使用綁定運行 – Chepene 2014-12-16 10:31:34

回答

22

您不能使用Inlines(在Run子節點)和TextBlock.Text在同一時間。

+0

是的您是對的。這解決了它。然而,這實際上與以下工作很好 \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t <運行文本=「{結合RFQNo}」 fontWeight設置= 「粗體」 前景=「#FFFFF504 「/> \t \t \t \t \t \t \t \t \t <運行文本= 「〜 」/> \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t <運行文本=「{結合狀態}」 fontWeight設置=「粗體「前景=」 #FF85F35F「/> \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t ' – scottsanpedro 2012-08-09 11:25:30

+0

謝謝你幫我。斯科特 – scottsanpedro 2012-08-09 11:28:51