joepetrakovich
joepetrakovich

Reputation: 1366

How do I make a TextBox that can grow wider than its parent?

Is there any way I can make a WPF TextBox dynamically grow beyond the bounds of its parent?

For example, I am allowing a user to type in an XPath string that could be very long (wide), I would like one of two possible things to happen:

  1. The textbox could grow wider when the user types a certain amount of characters. or
  2. When the user initially clicks on the textbox, it kind of 'pops-out' and is very wide, wider than its container.

Is this possible?

Upvotes: 3

Views: 818

Answers (2)

MichaelS
MichaelS

Reputation: 7103

You can try the following:

  1. Put both the ParentControl and the TextBox inside a Canvas.
  2. Locate the TextBox using fixed or dynamic coordinates relative to the ParentControl.
  3. Set the TextBox Z-Index to higher value of the ParentControl.
  4. Relocate and/or expend the TextBox based on TextBox events.

Upvotes: 0

Jens
Jens

Reputation: 25563

You can set a negative Margin to allow it to grow wider than its parent.

<Grid>
    <Grid Margin="50">
        <TextBlock Margin="0,0,-50,0" Text="This is a very long text." />
    </Grid>
</Grid>

Upvotes: 3

Related Questions