views:

211

answers:

3

How can I avoid TextBox vertical streching in following example:

<StackPanel Orientation="Horizontal">
  <Button Height="40">OK</Button>
  <TextBox Width="200"></TextBox>
</StackPanel>
A: 
    <StackPanel Orientation="Horizontal">
        <Button Height="40">OK</Button>
        <TextBox Height="40" Width="200"></TextBox>
    </StackPanel>
Whytespot
+3  A: 

Use the VerticalAlignment Property

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

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

Cory Larson