2012-08-09 65 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