I am using ElementHost to host WPF RichTextBox on my Windows Forms Form. The ElementHost fills the entire Panel by DockStyle.Fill. The problem is that WPF RichTextBox doesn't change it's Document's width when I try to change it using RichTextBox.Document.PageWidth property. I simply cannot increase the Document's size and so it wraps all text and everything when they reach the limit of width of Document. It seems a bug in WPF RichTextBox, or my own code implementation is wrong and some other code is to be implemented. Please inform me the correct code implementation which successfully changes the WPF RichTextBox Document width when I use WPF RichTextBox in Windows Forms Form.

I placed the code below in Form.Load Event.

            // host1 = ElementHost
            // rtbEntry = WPF RichTextBox
            host1.Dock = DockStyle.Fill;
            host1.AutoSize = true;
            host1.Child = rtbEntry;
            rtbEntry.Height = 10000;
            rtbEntry.Width = 10000;
            rtbEntry.HorizontalScrollBarVisibility = System.Windows.Controls.ScrollBarVisibility.Visible;
            rtbEntry.Document.PageWidth = (double)20000;
            rtbEntry.Document.MinPageWidth = (double)20000;
            rtbEntry.Document.MaxPageWidth = (double)20000;
            rtbEntry.VerticalScrollBarVisibility = System.Windows.Controls.ScrollBarVisibility.Visible;
            toolStripContainer2.ContentPanel.Controls.Add(host1);

I tried the code described above. I also tried very much to find correct code to solve this problem on Internet but there was none. Unless this problem is solved, my project is stuck with this problem.

0

There are 0 best solutions below