2013-08-28 137 views
1

的宽度文本框的元件设置宽度我有文本框的组合框为物品我喜欢文本框的宽度设置为组合框的宽度。因此,在时刻文本框与文本的大小扩大,但它应该换时宽度是一样的组合框... 这是我的XAML:C#WPF组合框与文本框作为作为组合框

<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> 

回答

2

尝试添加下面的伸展里面的文本框ComboBoxItems:

<ComboBox.ItemContainerStyle> 
    <Style TargetType="ComboBoxItem"> 
     <Setter 
      Property="HorizontalContentAlignment" 
      Value="Stretch"/> 
    </Style> 
</ComboBox.ItemContainerStyle> 
+0

感谢您的快速重播,但它确实有效 –