如何增加在WPF ComboBox中显示的项目数量?

huangapple go评论62阅读模式
英文:

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",但没有效果。

如何增加在WPF ComboBox中显示的项目数量?

英文:

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?

如何增加在WPF ComboBox中显示的项目数量?

Here's the XAML of the ComboBox:

&lt;DataTemplate x:Key=&quot;ItemTemplate&quot;&gt;
      &lt;WrapPanel&gt;
        &lt;Image Width=&quot;24&quot; Height=&quot;24&quot; Stretch=&quot;Fill&quot; Source=&quot;{Binding StateImage}&quot; VerticalAlignment=&quot;Center&quot; HorizontalAlignment=&quot;Center&quot; Margin=&quot;0,0,15,0&quot;/&gt;
        &lt;Label Content=&quot;{Binding Address}&quot; VerticalAlignment=&quot;Center&quot; HorizontalAlignment=&quot;Center&quot; /&gt;
      &lt;/WrapPanel&gt;
    &lt;/DataTemplate&gt;

&lt;ComboBox x:Name=&quot;CbxClients&quot; HorizontalAlignment=&quot;Center&quot; VerticalAlignment=&quot;Top&quot; ItemTemplate=&quot;{StaticResource ItemTemplate}&quot; Width=&quot;320&quot; Height=&quot;24&quot; IsEditable=&quot;False&quot; /&gt;

PS: MaxDropDownHeight seems not to do anything. I already set it to 1000 or "Auto" with no effect.

答案1

得分: 1

你可以尝试使用隐式的Style来修改Popup的高度:

&lt;ComboBox x:Name=&quot;CbxClients&quot; HorizontalAlignment=&quot;Center&quot; VerticalAlignment=&quot;Top&quot; 
              ItemTemplate=&quot;{StaticResource ItemTemplate}&quot; Width=&quot;320&quot; Height=&quot;24&quot; IsEditable=&quot;False&quot;&gt;
        &lt;ComboBox.Resources&gt;
            &lt;Style TargetType=&quot;Popup&quot;&gt;
                &lt;Setter Property=&quot;Height&quot; Value=&quot;1000&quot;/&gt;
            &lt;/Style&gt;
        &lt;/ComboBox.Resources&gt;
&lt;/ComboBox&gt;
英文:

You could try to modify the height of the Popup using an implicit Style:

&lt;ComboBox x:Name=&quot;CbxClients&quot; HorizontalAlignment=&quot;Center&quot; VerticalAlignment=&quot;Top&quot; 
          ItemTemplate=&quot;{StaticResource ItemTemplate}&quot; Width=&quot;320&quot; Height=&quot;24&quot; IsEditable=&quot;False&quot;&gt;
    &lt;ComboBox.Resources&gt;
        &lt;Style TargetType=&quot;Popup&quot;&gt;
            &lt;Setter Property=&quot;Height&quot; Value=&quot;1000&quot;/&gt;
        &lt;/Style&gt;
    &lt;/ComboBox.Resources&gt;
&lt;/ComboBox&gt;

huangapple
  • 本文由 发表于 2023年7月6日 16:07:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76626753.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定