【问题标题】:XAML TextBlock and Run bindingXAML TextBlock 和运行绑定
【发布时间】:2012-08-06 14:22:24
【问题描述】:

我遇到了 Run 绑定不起作用的问题。 这是我当前的代码。

<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>

【问题讨论】:

  • 显示你的binding errors...
  • 谢谢。没有显示绑定错误
  • 自 WPF 4.0 起您可以在运行中使用绑定

标签: wpf xaml


【解决方案1】:

您不能同时使用InlinesRun 子节点)和TextBlock.Text

【讨论】:

  • 是的,你是对的。那解决了它。然而,这实际上适用于以下&lt;TextBlock TextWrapping="Wrap" Text="{Binding RFQID}" FontWeight="Bold" Foreground="#FFFFF504" HorizontalAlignment="Left" Width="185"&gt; &lt;Run Text=" ~ "/&gt; &lt;Run Text="{Binding RFQNo}" FontWeight="Bold" Foreground="#FFFFF504"/&gt; &lt;Run Text=" ~ "/&gt; &lt;Run Text="{Binding Status}" FontWeight="Bold" Foreground="#FF85F35F"/&gt; &lt;/TextBlock&gt;
  • 感谢您帮助我。斯科特
猜你喜欢
  • 1970-01-01
  • 2013-03-26
  • 1970-01-01
  • 1970-01-01
  • 2017-11-13
  • 1970-01-01
  • 1970-01-01
  • 2021-09-06
  • 1970-01-01
相关资源
最近更新 更多