简体   繁体   English

文字换行不适用于WPF RichtextBox

[英]Text Wrap not working with WPF RichtextBox

I have a WPF User Control with a RichTextBox in it. 我有一个带有RichTextBox的WPF用户控件。 I am consuming this User Control in one the WPF pages. 我在一个WPF页面中使用了此用户控件。 Alongwith it, I am using a FlowDocumentPageViewer with a ListView in it. 与此同时,我正在使用带有ListView的FlowDocumentPageViewer。 Later on, I am assigning the data of ListView in the RichTextBox using a FlowDocument. 稍后,我将使用FlowDocument在RichTextBox中分配ListView的数据。 Everything goes well but the wrap functionality does not work in it. 一切正常,但是自动换行功能无法使用。

On behalf of @Sumit (who asked the question) 代表@Sumit(问了这个问题)

below is the code snippet which is currently being used. 以下是当前正在使用的代码段。

1) User Control with RichTextBox 1)使用RichTextBox进行用户控制

在此处输入图片说明

2) Method to bind FlowDocument to RichTextBox 2)将FlowDocument绑定到RichTextBox的方法

在此处输入图片说明

3)Consumer Page 3)消费页面 在此处输入图片说明

4) Consumer Page Code behind 4)消费者页面代码后面 在此处输入图片说明

To diagnose the problem for wrap functionality, I segregated the components being used in the current XAML code into different solutions. 为了诊断包装功能的问题,我将当前XAML代码中使用的组件隔离到不同的解决方案中。

Please refer the following description to understand the steps followed in the analysis:- 请参考以下说明以了​​解分析中遵循的步骤:-

  • A solution with List View having DataGrid (with two columns and multiple rows):- The wrap functionality was working in this solution. 具有DataGrid(具有两列和多行)的列表视图的解决方案:-包装功能在此解决方案中有效。
  • A solution with FlowDocumentPageViewer having FlowDocument with the ListView used in the above solution:- The wrap functionality was working in this solution. 在上述解决方案中使用的FlowDocumentPageViewer解决方案具有带有ListView的FlowDocument:-包装功能在此解决方案中有效。
  • A solution with the User Control(referred from MultiLinha) and above FlowDocumentPageViewer. 用户控件(从MultiLinha引用)及以上FlowDocumentPageViewer的解决方案。 The wrap functionality was not working in this solution. 包装功能在此解决方案中不起作用。

After isolating the components in this way, I observed that while integrating the User Control with FlowDocumentPageViewer the wrap functionality stopped working. 以这种方式隔离了组件之后,我观察到在将用户控件FlowDocumentPageViewer集成时,自动换行功能停止工作。

This was resolved when I put Style with property Text Wrapping set to Wrap for the FlowDocument itself. 这时候我把风格与属性文字环绕设置为包裹的FlowDocument的本身得到解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM