wpf XAML 中的“运行文本”标签是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29234619/
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-13 13:02:03  来源:igfitidea点击:

What does the "run text" tag mean in XAML?

c#wpfxaml

提问by xarzu

What does the "run text" tag mean in XAML?

XAML 中的“运行文本”标签是什么意思?

It kind of just appeared in the XAML apparently put there by expression blend. When I do a winmerge, I noticed it from a previous release of the code.

它刚刚出现在 XAML 中,显然是由表达式混合放在那里的。当我执行 winmerge 时,我从之前版本的代码中注意到了这一点。

Old:

老的:

<TextBlock VerticalAlignment="Bottom" Height="20" >^</TextBlock> 

New:

新的:

<TextBlock VerticalAlignment="Bottom" Height="20" ><Run Text="^"/></TextBlock>  

回答by paparazzo

TextBlock contains an Inlines collection
TextBlock.Inlines Property
Run is a type of Inline
Run is inline-level flow content
This is an example of multiple Inlines

TextBlock 包含一个 Inlines 集合
TextBlock.Inlines Property
Run 是一种 Inline
Run 是内联级流内容
这是多个内联的示例

<TextBlock Grid.Row="3" Name="myText" TextWrapping="Wrap">
    I go
    <LineBreak/>
    <Run FontStyle="Italic" Text="home"/>
</TextBlock>

回答by Scott Chamberlain

A TextBlockcan have more than just text as its content, it could be other controls. In your new version the content of the TextBlockis a System.Windows.Documents.Runwith its Textproperty set to ^.

ATextBlock的内容不仅可以是文本,还可以是其他控件。在您的新版本中, 的内容TextBlock是 a System.Windows.Documents.Run,其Text属性设置为^

This was likely done by Expression Blend because ^could be considered a control character in some cases. By putting the text inside a Runit removes any ambiguity that the ^is text and not some control character. When dealing with a complex designer it is always best to remove as much ambguitity as possible so Blend likely just did it to make it easier on its own parsing engine.

这可能是由 Expression Blend 完成的,因为^在某些情况下可能被视为控制字符。通过将文本放在 a 中,Run它消除了^文本而不是某些控制字符的任何歧义。在与复杂的设计师打交道时,最好尽可能消除歧义,因此 Blend 可能只是为了让自己的解析引擎更容易做到这一点。

回答by Sk Victor

You can use RunText many times inside a TextBlock. For every text if you dont want to use many TextBlocks and this will be shown in runtime.

您可以在 TextBlock 内多次使用 RunText。对于每个文本,如果您不想使用许多 TextBlock,这将在运行时显示。