Matt H.
Matt H.

Reputation: 10786

Create an Auto-sized RichTextBox in Custom WPF control (VB.NET)

I have previously used the arguments of a contentsResized event on a Winforms richtextbox to get the new size of my RTB.

I am now developing a WinForms app with a custom WPF RichTextBox. My whole reason for doing this is to use the out-of-the-box spellchecker.

I need my RichTextBox to expand and collapse vertically as the text is changed. The elementhost will also have to resize to allow the whole RTB to display on-screen.

Upvotes: 0

Views: 1017

Answers (1)

Oskar
Oskar

Reputation: 8175

If what you want is to make your RichTextBox only be as high as needed, put it in a StackPanel like this

<Window x:Class="WpfApplication3.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
  <StackPanel>
    <RichTextBox Background="Azure" />
  </StackPanel>
</Window>

Otherwise please explain in more detail what your problem is, and if possible post the code that is not working.

Upvotes: 1

Related Questions