Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting dropdown height of a combobox in WPF

Tags:

combobox

wpf

I have a combobox in WPF that I add items to at run-time (via a data binding to a List). I'd like to set the height of the dropdown box dynamically so that all (or most) of the items show. Unfortunately it seems that the height of the dropdown is set once and cannot be dynamically altered. It always seems to be the same size.

Is there some relatively straightforward to adjust the dropdown height?


Yes, I've tried setting it after adding the items to the combobox. In the debugger it looks like the new value is there. However, when I open the dropdown, it drops down to a size of its own choosing. I've tried exaggerating the MaxDropDownHeight and have even set it to "Auto" to no avail.

like image 981
The ChiliCat Avatar asked Jan 02 '09 15:01

The ChiliCat


2 Answers

The property MaxDropDownHeight is a dependency property, on the combo box that controls the height of the drop down list. Since it's a dependency property, it's value can be set dynamically.

Have you tried setting this value?

MaxDropDownHeight="Auto"
like image 110
w4g3n3r Avatar answered Nov 02 '22 18:11

w4g3n3r


For me, the issue was that ComboBox dropdown had height of 95 pixels regardles of the amount of items.

My data source for the ComboBox was a Collection<>, but after changing it to ObservableCollection<>, the ComboBox dropdown opens showing all items.

Now also the MaxDropDownHeight property works just fine.

Ref: This comment in here Make the dropdown of a combobox be shorter?

like image 26
kimmoli Avatar answered Nov 02 '22 19:11

kimmoli