简体   繁体   中英

How can I change WPF ComboBox dropdown width in C#

I'm currently working on C# WPF project, one thing I can't seem to do is - How do I change the ComboBox dropdown width, because every time I had Items the dropdown width takes the size of the longest item(or string);

How can I fix this Please Help fellow developers/programmers !!!!

Set the ItemContainerStyle of the ComboBoxItem like this:

 <ComboBox Width="50" Height="40">
        <ComboBox.ItemContainerStyle>
            <Style TargetType="ComboBoxItem">
                <Setter Property="Width" Value="60"/>
            </Style>
        </ComboBox.ItemContainerStyle>
        <ComboBoxItem Content="this is Item One "/>
        <ComboBoxItem Content="this is Item "/>
        <ComboBoxItem Content="this is "/>
        <ComboBoxItem Content="this "/>
    </ComboBox>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM