Reputation: 10237
In my comboBoxes that have many items (> 10), I need to either: (a) Have all of the items display when the dropdown occurs -or: (b) Reduce the space between the items (it seems excessive, almost "cartoonish")
So, I would really prefer both. How can I do one or the other or both?
It would seem the MaxDropDownHeight property would be just the ticket, but set to Infinity it doesn't work/has a strange definition of Infinity.
Here's the XAML for one of them with this problem:
<ComboBox x:Name="comboBoxDay" Grid.Row="4" Grid.Column="5" Margin="8" IsEnabled="False"></ComboBox>
...and what it contains:
for (int i = 1; i < 32; i++)
{
comboBoxDay.Items.Add(i);
}
Setting the height to 15 cuts off part of the text; so does 18. And even then, only March-November are displayed. I also set MaxDropDownHeight to first 320, then 520. Here's the entire XAML for the comboBox in question:
<ComboBox x:Name="comboBoxFromMonth" Grid.Row="1" Grid.Column="1"
Height="24" Width="80" MaxDropDownHeight="520" HorizontalAlignment="Left"
VerticalAlignment="Center" Margin="4">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Height="20" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
...(January, February, and December still do not display without scrolling, although there is plenty of room below - real estate is not the problem).
It would seem all items in a comboBox should display BY DEFAULT, not require jumping through hoops to get it all to display...at least with a reasonable amount of items (42 or fewer).
Upvotes: 0
Views: 3794
Reputation: 17
I also was trying to get the Popup to appear downwards and eventually I set the Margin after editing the template. In the given link there is a command PopupPlacement given but it is not working in WinRT. But this hint helped me to get the idea.
Upvotes: 0
Reputation: 102733
For (a), you're right, you can use MaxDropDownHeight
, but it will only go to the top/bottom of the screen, and no further. To make it fill the screen vertically, you'll need to modify the default Control Template and give the Popup's Placement
property a different value (eg, Center
):
For (b) you can reduce the space between elements by defining an ItemTemplate
:
<ComboBox>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Height="15" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Upvotes: 1