How to resize the dropdown list of the ComboBox in UWP?

Xie Steven 831 Reputation points
2020-07-10T14:06:28.553+00:00

Hello guys,

I have such a requirement. I need to set a fixed size for the combobox. It's easy to achieve it by setting the width and height. But now, I also need to set a fixed size for the dropdownList(Popup) of the combobox. With my tests, it's impossible. I tried to edit its style, it didnot work.

Is it possible to resize the dropdownlist of the combobox?

Best Regards,
Xavier

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Richard Zhang-MSFT 6,936 Reputation points
    2020-07-10T14:24:07.703+00:00

    Hello,

    Welcome to Microsoft Q&A.

    The width of the combo box's drop-down list is determined by the max-width of a items, and the overall height is determined by ComboBox.MaxDropDownHeight.

    Here is a example:

    xaml

    <Grid>
        <ComboBox x:Name="TestComboBox" MaxDropDownHeight="200"
                  ItemsSource="{x:Bind TestCollection}">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding}" TextTrimming="CharacterEllipsis"
                               Width="150"/>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
    </Grid>
    

    xaml.cs

    public ObservableCollection<string> TestCollection = new ObservableCollection<string>();
    public TestPage()
    {
        this.InitializeComponent();
        for (int i = 0; i < 1000; i++)
        {
            TestCollection.Add(i.ToString());
        }
    }
    

    In this way, the size of the drop-down list can be limited to 150x200.


    Update

    The size of the ComboBox drop-down list will change based on the size of the internal elements, but it cannot be less than the value of the established ComboBox.Width.

    In ComboBox, there is a property is TemplateSettings, this property is read-only, and this property represents some style properties when ComboBox is created, including DropDownContentMinWidth and DropDownOpenedHeight, etc., they are all read-only.

    This means that these properties will be assigned and created internally after the ComboBox is instantiated, and currently cannot be modified from the outside.

    So if you create a ComboBox with a width of 300, the minimum width of the drop-down list is 300. However, currently the maximum height can be modified by ComboBox.MaxDropDownHeight

    Thanks.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.