Blog on software engineering
Setting 100% width and 100% height for a Textbox in WPF

Setting 100% width and 100% height for a Textbox in WPF

If you want to stretch a textbox to the width of the window in WPF you can use the following code



<Window x:Class="Ada.Eac.UI.DeployWindow"
        Title="DeployWindow" Height="300" Width="988" SnapsToDevicePixels="True" UseLayoutRounding="True" WindowState="Maximized" WindowStartupLocation="CenterScreen" Icon="/Eac;component/Dashboard.ico">
            <ColumnDefinition Width="*"></ColumnDefinition>
            <RowDefinition Height="60"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        <Button Grid.Column="1" Content="Deploy" Height="30" Width="100" HorizontalAlignment="Left" Margin="10,10,10,10" Name="deployButton" Cursor="Hand" />
        <TextBox Grid.Column="1" Grid.Row="2"  HorizontalAlignment="Stretch" Name="outputTextBox" Margin="10,10,10,10" VerticalAlignment="Stretch" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" />






  1. I tried putting my TextBox in a Grid and it didn’t help, even with the Horz and Vert align set to Stretch as shown. After some frustration I figured out that its not just the immediate container of the TextBox that’s important, but also what container the Grid is in. I had my Grid inside a StackPanel and the StackPanel was forcing the Grid to be as small as possible, thus the TextBox wouldn’t expand either.


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.