Reputation: 1742
Is there a simple way to prevent a RichTextBox from increasing its height when you add more lines to it?
What I have tested so far:
None of the above helps however. The RTB is inside a Grid row that is autosizing and the user can control the row height with a GridSplitter. I want the RTB to honor the splitter and not auto-resize as more text gets submitted.
Worth noting, incidentally, is that once I resize the Grid.Row (with the GridSplitter) the RTB is restrained and can no longer autogrow. I guess that if I could just, somehow, emulate resizing , just a pixel, when the form loads it would "solve" the issue. A bit hackish of course ...
(Relevant XAML example)
<Window
x:Class="Test.Window"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="TEST"
Height="609.8" Width="848"
Background="#000000"
FontFamily="Segoe UI"
>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="150" MinWidth="100"/>
<ColumnDefinition Width="3"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="3" />
<RowDefinition Height="Auto" MinHeight="100" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel
Grid.Row="1" Grid.Column="0"
Orientation="Vertical"
Background="#333333"
>
</StackPanel>
<Grid
Grid.Row="1" Grid.Column="1"
Width="Auto"
HorizontalAlignment="Stretch"
Background="#222222"
/>
<GridSplitter
Grid.Row="1" Grid.Column="2"
HorizontalAlignment="Stretch" Width="3" Background="#222222"
/>
<Grid
Grid.Row="1" Grid.Column="3"
MinWidth="100"
/>
<GridSplitter
Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4"
HorizontalAlignment="Stretch" Height="3" Background="#222222" />
<Grid Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4">
<Grid>
<RichTextBox MinHeight="50" VerticalAlignment="Stretch">
<RichTextBox.Document>
<FlowDocument>
<Paragraph>
<Run Text="Lorem ipsum dolor sit amet consectetur adipiscing elit tempor, class a cum odio diam nec ullamcorper eget, duis curae dictum rutrum cursus tristique rhoncus. Curabitur montes erat sociis feugiat dictumst eu faucibus, dapibus habitasse platea parturient dignissim fringilla tortor, et ridiculus vehicula ac vel sem."></Run>
</Paragraph>
</FlowDocument>
</RichTextBox.Document>
</RichTextBox>
</Grid>
</Grid>
</Grid>
</Window>
Upvotes: 0
Views: 425
Reputation: 12993
A simple way, set a height to the RTB (or to the Grid Row in which the RTB is placed).
It keeps growing since there is no set boundary. Its parent, the Grid, is autosized with its children, so the children are spoiled.
Upvotes: 1