Question

How can I avoid TextBox vertical streching in following example:

<StackPanel Orientation="Horizontal">
  <Button Height="40">OK</Button>
  <TextBox Width="200"></TextBox>
</StackPanel>
Was it helpful?

Solution

Use the VerticalAlignment Property

<StackPanel Orientation="Horizontal">
  <Button Height="40">OK</Button>
  <TextBox Width="200" VerticalAlignment="Center"></TextBox>
</StackPanel>

OTHER TIPS

    <StackPanel Orientation="Horizontal">
        <Button Height="40">OK</Button>
        <TextBox Height="40" Width="200"></TextBox>
    </StackPanel>

From MSDN:

Setting the TextWrapping attribute to Wrap causes entered text to wrap to a new line when the edge of the TextBox control is reached, automatically expanding the height of the TextBox control to include room for a new line, if necessary.

So, to fix it, I think you can set TextWrapping = TextWrapping.NoWrap

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top