I have a text box in a grid, the textbox has a style applied to it in which I am trying to bind the width to the colum width in the grid.
window.xaml
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Content="Register User" Grid.Column="0" Grid.Row="0" Style="{StaticResource LabelStyle}"/>
<Label Content="User Name: " Grid.Column="0" Grid.Row="1" Style="{StaticResource LabelStyle}"/>
<TextBox Grid.Column="1" Grid.Row="1" Style="{StaticResource TextBoxStyle}"/>
</Grid>
DefaultStyle.xaml
<Style TargetType="{x:Type Label}" x:Key="LabelStyle">
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style TargetType="{x:Type TextBox}" x:Key="TextBoxStyle">
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Width" Value="{<!--?????????--!>}"/>
</Style>
I have tried a few thing but can’t work out how to bind this.
Instead of setting the Width, just set
HorizontalAlignment="Stretch"