9 December, 2010
2 Comments
1 category
If you want to stretch a textbox to the width of the window in WPF you can use the following code
Code
<Window x:Class="Ada.Eac.UI.DeployWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="DeployWindow" Height="300" Width="988" SnapsToDevicePixels="True" UseLayoutRounding="True" WindowState="Maximized" WindowStartupLocation="CenterScreen" Icon="/Eac;component/Dashboard.ico"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"></ColumnDefinition> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="60"></RowDefinition> <RowDefinition Height="*"></RowDefinition> </Grid.RowDefinitions> <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" /> </Grid> </Window>
Screendump
Tags: WPF
Category: Uncategorized
Thanks for HorizontalAlignment property
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.