C#/WPF:禁用 RichTextBox 的文本换行
有谁知道如何禁用 RichTextBox
的文本换行? 例如,如果我有一个不适合窗口的大字符串,则 RichTextBox
会放置无法在新行中显示的字符串部分。我想禁用它(并仅通过使用滚动条使其可见)。
多谢。
干杯
Does anyone know how I can disable the text wrapping of a RichTextBox
?
E.g. if I have a large string which doesn't fit in the window, the RichTextBox
places the part of the string which can't be shown of a new line. I want to disable that (and make it visible only by using the Scrollbar
).
Thanks a lot.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
RichTextBox
在 WPF 中,它只是FlowDocument< 的编辑器/代码>
。
根据 MSDN:
因此,虽然您无法显式禁用
RichTextBox
的自动换行,但您可以执行以下操作:这将具有基本上相同的预期效果,直到您有一行超出 <代码>页面宽度。
注意(截至 2015 年 7 月):VS2015 RC 允许
wordwrap = false
完全按照 OP 的预期工作。我相信 Visual Studio 的早期版本也是如此。A
RichTextBox
in WPF is simply an editor for aFlowDocument
.According to MSDN:
So, while there's no way for you to explicitly disable the word-wrapping of a
RichTextBox
, you can do something like this:Which will have essentially the same desired effect until you have a line that exceeds the
PageWidth
.Note (as of July 2015): VS2015 RC allows
wordwrap = false
to work precisely as OP seems to desire. I believe earlier versions of Visual Studio did also.由于没有答案让我满意,这是我的解决方案:
问题是关于性能,取决于文本长度和刷新频率。
Since no answer was satisfying for me, here is my solution:
Question is about performance depending on text length and how often it is refreshed.
我还需要显示一个大字符串并尝试了 RichTextBox,但我不喜欢将文档的 PageWidth 设置为固定大小的解决方案。滚动条始终可见,并且滚动区域太大。
如果 TextBlock 足够了,您可以使用它并将其放置在 ScrollViewer 中。它非常适合我,因为我不需要 RichTextBox 的所有额外功能。
I also needed to display a large string and tried the RichTextBox but I did not like the solution with setting the PageWidth of the Document to a fixed size. The scrollbar would be visible all the time and the scrolling area was be to big.
If a TextBlock is sufficient you can use that instead and place it inside a ScrollViewer. It worked perfect for me since I did not need all the extra features of the RichTextBox.
如果您不想显示水平滚动条,请在 ScrollViewer 上强制使用 MinWidth:
If you don't want to show the horizontal scrollbar, enforce a MinWidth on the ScrollViewer:
VerticalScrollBar:
VerticalScrollBarVisibility="自动" MaxHeight="200"
HorizontalScrollBar:
HorizontalScrollBarVisibility="自动" MaxWidth="400"
VerticalScrollBar :
VerticalScrollBarVisibility="Auto" MaxHeight="200"
HorizontalScrollBar :
HorizontalScrollBarVisibility="Auto" MaxWidth="400"
适合我的解决方案。这个想法取自 在这里。
XAML中定义
我在代码中的
Suitable solution for me. The idea was taken from here.
I defined in XAML
In Code