Get all text in multiline wpf textblock
wpf
Solution
You can try this:
StringBuilder s = new StringBuilder();
foreach (var line in tb.Inlines)
{
if (line is LineBreak)
s.AppendLine();
else if (line is Run)
s.Append(((Run) line).Text);
}
var text = s.ToString();
Found it here
Problem
I have Multiline TextBlock, I want to get all it's lines by code Can someone help me? The TextBlock: ``` <TextBlock Name="tb" TextWrapping="Wrap" > Name:_____________ <LineBreak/> Mark:____________ </TextBlock> ``` In C#: ``` text = ((TextBlock)tb).Text; ``` But I got only the first line. Thanks!