[英]DataReader into WPF TextBox vs RichTextBox
When I set the TextBox.Text property equal to DataReader.GetString(x), my data displays correctly. 当我将TextBox.Text属性设置为等于DataReader.GetString(x)时,我的数据将正确显示。
while (dr.Read())
{
string data = dr.GetString(2);
contentTextBox.Text = data;
}
However, I'm trying to use a RichTextBox instead of a TextBox to take advantage of the RichTextBox.Find method, but when I do this it fills the RichTextBox with a new line after each character 但是,我试图使用RichTextBox而不是TextBox来利用RichTextBox.Find方法,但是当我这样做时,它会在每个字符之后用新行填充RichTextBox
while (dr.Read())
{
string data = dr.GetString(2);
contentRichTextBox.AppendText(data);
}
How can I get the string data into the RichTextBox with the correct formatting (ie: the same way that it is read into TextBox.Text)? 如何将字符串数据以正确的格式放入RichTextBox中(即:与将其读入TextBox.Text的方式相同)?
Thanks! 谢谢!
@jdweng suggested that the RichTextBox was not wide enough. @jdweng建议RichTextBox不够宽。 This was definitely one of the issues since its width was set to "Auto." 由于其宽度设置为“自动”,因此这绝对是问题之一。 Even though the regular TextBox automatically resizes based on content if it's Width="Auto", RichTextBox does not resize that way. 即使常规TextBox的Width =“ Auto”根据其内容自动调整大小,RichTextBox也不会以这种方式调整大小。
Update: Was able to get the RichTextBox to resize based on content/window resize by adding a FlowDocument tag with its "PageWidth" bound to the RichTextBox: 更新:通过添加FlowDocument标签并将其“ PageWidth”绑定到RichTextBox上,能够根据内容/窗口调整大小来调整RichTextBox的大小:
<RichTextBox Name="contentTextBox" Height="Auto" Width="Auto">
<FlowDocument PageWidth="{Binding ElementName=contentTextBox, Path=ActualWidth}" />
</RichTextBox>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.