获取多行 wpf 文本块中的所有文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16133200/
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 08:38:44 来源:igfitidea点击:
Get all text in multiline wpf textblock
提问by mich
I have Multiline TextBlock, I want to get all it's lines by code Can someone help me?
我有 Multiline TextBlock,我想通过代码获取所有行 有人可以帮助我吗?
The TextBlock:
文本块:
<TextBlock Name="tb" TextWrapping="Wrap" >
Name:_____________
<LineBreak/>
Mark:____________
</TextBlock>
In C#:
在 C# 中:
text = ((TextBlock)tb).Text;
But I got only the first line.
但我只得到了第一行。
Thanks!
谢谢!
回答by Johan Larsson
回答by kamlendra
回答by Dragos Stoica
If you want to display on multiple lines you can use :
如果要显示在多行上,可以使用:
<TextBlock Name="myText" Text="I go 
 Home " >
and sure, you can get all lines by parsing the string.
当然,您可以通过解析字符串来获取所有行。

