The width of the window includes elements such as the border, and the height includes elements such as the title bar. Therefore, you need to consider this when setting the width / height. You can use the SizeToContent option in the window so that the size is such that it matches the text fields.
how
<Window ... SizeToContent="Width"
Or you can replace your StackPanel with a grid to give each TextBox window width the available window width:
<Grid> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <TextBox Grid.Column="0">Hello</TextBox> <TextBox Grid.Column="1" TextAlignment="Right">World</TextBox> </Grid>
source share