我想弄清楚如何制作一个长文本框。我知道一旦文本框大于2048就会出现问题。但是如果你撰写的电子邮件大于那个没有问题的电子邮件。电子邮件使用什么类型的控件?
<ScrollViewer>
<TextBox />
</ScrollViewer>
答案 0 :(得分:0)
此blog post涵盖了此问题的解决方案。基本上你必须在多个TextBlocks之间拆分文本,然后将它们添加到StackPanel。
private void ParseText(string value)
{
if (this.stackPanel == null)
{
return;
}
// Clear previous TextBlocks
this.stackPanel.Children.Clear();
// Calculate max char count
int maxTexCount = this.GetMaxTextSize();
if (value.Length < maxTexCount)
{
TextBlock textBlock = this.GetTextBlock();
textBlock.Text = value;
this.stackPanel.Children.Add(textBlock);
}
else
{
int n = value.Length / maxTexCount;
int start = 0;
// Add textblocks
for (int i = 0; i < n; i++)
{
TextBlock textBlock = this.GetTextBlock();
textBlock.Text = value.Substring(start, maxTexCount);
this.stackPanel.Children.Add(textBlock);
start = maxTexCount;
}
// Pickup the leftover text
if (value.Length % maxTexCount > 0)
{
TextBlock textBlock = this.GetTextBlock();
textBlock.Text = value.Substring(maxTexCount * n, value.Length - maxTexCount * n);
this.stackPanel.Children.Add(textBlock);
}
}
}