英文:
How to increase number of items shown in WPF ComboBox?
问题
我的 WPF ComboBox 的下拉区域非常小,只显示了三个项目和一个滚动条。有办法使下拉区域变大,以便显示更多项目吗?
以下是 ComboBox 的 XAML:
<DataTemplate x:Key="ItemTemplate">
<WrapPanel>
<Image Width="24" Height="24" Stretch="Fill" Source="{Binding StateImage}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,15,0"/>
<Label Content="{Binding Address}" VerticalAlignment="Center" HorizontalAlignment="Center" />
</WrapPanel>
</DataTemplate>
<ComboBox x:Name="CbxClients" HorizontalAlignment="Center" VerticalAlignment="Top" ItemTemplate="{StaticResource ItemTemplate}" Width="320" Height="24" IsEditable="False" />
PS:MaxDropDownHeight 似乎没有起作用。我已经将其设置为 1000 或 "Auto",但没有效果。
英文:
My WPF ComboBox has a very tiny drop down area. Thus only three items and a scrollbar are shown. Is there a way to make the drop down area bigger, so that more items become visible?
Here's the XAML of the ComboBox:
<DataTemplate x:Key="ItemTemplate">
<WrapPanel>
<Image Width="24" Height="24" Stretch="Fill" Source="{Binding StateImage}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,15,0"/>
<Label Content="{Binding Address}" VerticalAlignment="Center" HorizontalAlignment="Center" />
</WrapPanel>
</DataTemplate>
<ComboBox x:Name="CbxClients" HorizontalAlignment="Center" VerticalAlignment="Top" ItemTemplate="{StaticResource ItemTemplate}" Width="320" Height="24" IsEditable="False" />
PS: MaxDropDownHeight seems not to do anything. I already set it to 1000 or "Auto" with no effect.
答案1
得分: 1
你可以尝试使用隐式的Style
来修改Popup
的高度:
<ComboBox x:Name="CbxClients" HorizontalAlignment="Center" VerticalAlignment="Top"
ItemTemplate="{StaticResource ItemTemplate}" Width="320" Height="24" IsEditable="False">
<ComboBox.Resources>
<Style TargetType="Popup">
<Setter Property="Height" Value="1000"/>
</Style>
</ComboBox.Resources>
</ComboBox>
英文:
You could try to modify the height of the Popup
using an implicit Style
:
<ComboBox x:Name="CbxClients" HorizontalAlignment="Center" VerticalAlignment="Top"
ItemTemplate="{StaticResource ItemTemplate}" Width="320" Height="24" IsEditable="False">
<ComboBox.Resources>
<Style TargetType="Popup">
<Setter Property="Height" Value="1000"/>
</Style>
</ComboBox.Resources>
</ComboBox>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论