[英]How can I reduce the spacing between comboBox items and/or show all of the items?
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") 在我的包含许多项目(> 10)的comboBoxes中,我需要:(a)在出现下拉菜单时显示所有项目-或:(b)减少项目之间的空间(似乎过多,几乎是“卡通化”的) ”)
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. 看起来MaxDropDownHeight属性只是票证,但设置为Infinity则无效/具有对Infinity的奇怪定义。
Here's the XAML for one of them with this problem: 这是其中一个存在此问题的XAML:
<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; 将高度设置为15会截断部分文字; so does 18. And even then, only March-November are displayed. 18也是如此。即使这样,也只显示3月至11月。 I also set MaxDropDownHeight to first 320, then 520. Here's the entire XAML for the comboBox in question: 我还将MaxDropDownHeight设置为前320,然后是520。这是有问题的comboBox的整个XAML:
<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). ...(尽管下方有足够的空间,但仍不滚动显示1月,2月和12月-房地产不是问题)。
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). 看来comboBox中的所有项目都应按默认显示,而不需要跳过篮球才能全部显示...至少要包含合理数量的项目(42个或更少)。
For (a), you're right, you can use MaxDropDownHeight
, but it will only go to the top/bottom of the screen, and no further. 对于(a),您是对的,您可以使用MaxDropDownHeight
,但是它只会转到屏幕的顶部/底部,而不会进一步。 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
): 为了使其垂直填充屏幕,您需要修改默认的控制模板,并为Popup的Placement
属性赋予其他值(例如Center
):
For (b) you can reduce the space between elements by defining an ItemTemplate
: 对于(b),您可以通过定义ItemTemplate
来减少元素之间的ItemTemplate
:
<ComboBox>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Height="15" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
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. 在给定的链接中,给出了一个命令PopupPlacement,但在WinRT中不起作用。 But this hint helped me to get the idea. 但是这个提示帮助我理解了这个想法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.