I have this WPF app that displays a label, a button and a text box like so:
After adding three more lines via the button the windwos starts to grow with the textbox:
Here's the XAML:
<Window x:Class="_99_TestWPFApp.MainWindow"
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="Simple WPF Test App" Height="Auto" Width="Auto" SizeToContent="WidthAndHeight">
<Grid x:Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Content="A LABEL" "/>
<Button Grid.Row="1" Grid.Column="0" x:Name="btnAdd" Click="btnAdd_Click" Content="ADD LINE" />
<TextBox Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" VerticalScrollBarVisibility="Visible" Width="150"/>
</Grid>
In order to bind the height of the textbox to the height of the grid, I also added this to the textbox Height="{Binding ElementName=MainGrid, Path=ActualHeight}"
but to no effect.
I want the window and grid size to be fixed while the textbox displays its contents via a scrollbar
Is this even possible ? Or do I have to set a fixed height somewhere (e.g. for the window) ?