Is it possible to position a control in the XAML definiton relative to another control?
for example if I want to place a control exactly in the middle of another wider control.
and if so - how?
If you want to center the controls you could wrap them in a grid:
<Grid>
<TextBox Height="132" Width="229" VerticalAlignment="Center" HorizontalAlignment="Center" />
<Button Content="Button" Height="23" Width="75" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Grid>
Other positioning can be accomplished by other panels like StackPanel etc. Grid beeing the most flexible choice.
Edit: updated with grid and columns for controlling position:
<Grid Height="50" Width="200">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50*" />
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="75*" />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" Background="Red" />
<Button Content="Button" Grid.Column="2" />
</Grid>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With