wpf XAML 文本块和运行绑定

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11882066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 23:29:02  来源:igfitidea点击:

XAML TextBlock and Run binding

wpfxaml

提问by scottsanpedro

I have a problem where the binding of the Run does not work. Here's my current code.

我遇到了 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>

I am getting the company name appears but the extra data never shows up. Any ideas why this type of binding fails?

我得到了公司名称,但额外的数据从未出现。任何想法为什么这种类型的绑定失败?



Alternate Answer Along With Final Answer

替代答案以及最终答案

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

回答by H.B.

You cannot use the Inlines(the Runchild nodes) and the TextBlock.Textat the same time.

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