1

I have a combobox with Textboxes as Items i like to set the width of Textboxes to the width of Combobox. So at moment the Textbox expand with the size of text but it should wrap when width is the same as the combobox... this is my xaml:

<ComboBox  
            Margin="51,146,238,146"
            BorderThickness="0"
            HorizontalAlignment="Stretch" 
            HorizontalContentAlignment="Stretch"                                                   
            Padding="3" Height="20" IsEditable="True"
            x:Name="testCombobox" SelectionChanged="testCombobox_SelectionChanged">


            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBox 
                                                    TextWrapping="Wrap"
                                                    AcceptsReturn="True"

                                                    Padding="1,1,1,1"
                                                    Background="Yellow">
                    </TextBox>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>

1 Answer 1

3

Try to add the following to stretch the TextBoxes inside the ComboBoxItems:

<ComboBox.ItemContainerStyle>
    <Style TargetType="ComboBoxItem">
        <Setter
            Property="HorizontalContentAlignment"
            Value="Stretch"/>
    </Style>
</ComboBox.ItemContainerStyle>
Sign up to request clarification or add additional context in comments.

Comments

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.