Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpf textbox textwrapping

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.

like image 860
Jose Avatar asked May 19 '09 18:05

Jose


1 Answers

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!

like image 105
Mark Carpenter Avatar answered Oct 30 '22 03:10

Mark Carpenter