0

I have a listbox with a textbox

The textbox is defined in a datatemplate that ends like this

    <TextBlock Grid.Row="4" Grid.Column="0" Text="Note"></TextBlock>
    <TextBox Height="Auto" Grid.Row="4" Grid.Column="1" 
        Text="{Binding PartData.Note}" AcceptsReturn="True" TextWrapping="Wrap" >
    </TextBox>
</Grid>

I want the textbox to expand when the user enters multiple rows but it doesnt. The rowdefintion height is set to *

2 Answers 2

3

I've tried your sample with this code, and it works (use Shift-Enter to start a new row inside TextBox)

<Window x:Class="TextBoxWrap.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ListBox Height="140" ItemsSource="{Binding}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>

                        <TextBlock Grid.Row="1" Grid.Column="0" Text="Note"/>
                        <TextBox Margin ="10, 0,0,0" Height="Auto" Grid.Row="1" Grid.Column="1" Text="{Binding Count}" 
                            AcceptsReturn="True" TextWrapping="Wrap" />
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>       
      </Grid>
</Window>
Sign up to request clarification or add additional context in comments.

1 Comment

Found it , i had added a initital size on the row and then its locked. I changed it and added inital size on the textbox instead and then it works
0

You need to add

VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"

to TextBox so it takes all available space.

1 Comment

No , didnt work textbox is still fixed and does not expand with the text

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.