tags:

views:

1053

answers:

4

I need some help. Don't know if this is possible. I want to have the following:

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <TextBox TextWrapping="Wrap" MinLines ="5"/>
    </Grid>

which is a textbox wrapping inside of a grid column with width *. I want the textbox to take all the width available(hence *) but when a user adds text I want it to wrap when it gets to the end of the line(with the space available).

Currently the above will give a textbox with the entire width but when text is entered the width of the textbox just grows with the text.

I know i can set MaxWidth=?, but the point the column is * is that I don't know what the size of the column is.

I would like to say to the textbox "don't grow, whatever wpf gives you take it and don't increase one more pixel above that".

I think what I want is impossible, because wpf asks the control how big it wants to be and when the user adds more text that goes beyond the boundary it kindly requests more space and goes off expanding its width to infinity.

+2  A: 

Try binding the MaxWidth property of your TextBox to the ActualWidth property of your starred column (you'll have to name your column to do this). I'm pretty sure I've done something like this in the past.

Something like:

MaxWidth={Binding ElementName=MyColumn, Path=ActualWidth}

Good luck!

Pwninstein
+1  A: 

Seems to work properly for me when I set Grid.Column="1" on the TextBox.

RandomEngy
+1 Good call, I didn't notice that the TextBox wasn't told to be displayed in the second column (as he intends it). :)
Pwninstein
I'm assuming he wants it in column 0.
Chris Persichetti
He states above: "...which is a textbox wrapping inside of a grid column with width *". The Column with Width="*" is the second column (Grid.Column="1").
Pwninstein
That was a typo, I want it in column 1
Jose
+1  A: 

Looks like wpf-textbox-and-scroll-behavior question is similar to this one.

Chris Persichetti
A: 

In addition to what RandomEngy says about Grid.Column="1", you may also have to set some alignment properties on the Grid itself, particularly if it's set inside another container with different child Stretch behavior (e.g. a StackPanel)

micahtan