我有一个带有Textboxes作为Items的组合框我喜欢将Textboxes的宽度设置为Combobox的宽度。所以,当文本框随文本大小扩展时,它应该在宽度与组合框相同时换行... 这是我的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>
答案 0 :(得分:3)
尝试添加以下内容以拉伸ComboBoxItems中的TextBox:
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Setter
Property="HorizontalContentAlignment"
Value="Stretch"/>
</Style>
</ComboBox.ItemContainerStyle>