WPF设置ConboBox子项选择不出现滚动条

发布时间 2023-11-16 17:36:29作者: 青丝·旅人

当ComboBox子项过多时,下拉子项会出现滚动条,这样十分不美观

那么怎么解决呢,十分简单,只需要设置ComboBox的【MaxDropDownHeight】为【Auto】即可

示例代码:(其中 MaxDropDownHeight="Auto" 就是解决代码)

                                                       <ComboBox Style="{StaticResource Combobox_Base}" Grid.Column="1" Grid.Row="0"
                                                                  Height="30" FontSize="13" IsEditable="False" Width="Auto"
                                                                  VerticalContentAlignment="Center" Margin="6,0,6,0"
                                                                  MaxDropDownHeight="Auto">
                                                            <ComboBoxItem Content="CP" Height="40" IsSelected="True"/>
                                                            <ComboBoxItem Content="PP" Height="40"/>
                                                            <ComboBoxItem Content="Udc" Height="40"/>
                                                            <ComboBoxItem Content="Idc" Height="40"/>
                                                            <ComboBoxItem Content="Uaux" Height="40"/>
                                                            <ComboBoxItem Content="Iaux" Height="40"/>
                                                            <ComboBoxItem Content="UL1" Height="40"/>
                                                            <ComboBoxItem Content="UL2" Height="40"/>
                                                            <ComboBoxItem Content="UL3" Height="40"/>
                                                            <ComboBoxItem Content="IL1" Height="40"/>
                                                            <ComboBoxItem Content="IL2" Height="40"/>
                                                            <ComboBoxItem Content="IL3" Height="40"/>
                                                        </ComboBox>