如何在 C# 中更改 WPF ComboBox 下拉宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28005647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I change WPF ComboBox dropdown width in C#
提问by Jo?l Phaka
I'm currently working on C# WPF project, one thing I can't seem to do is - How do I change the ComboBox dropdown width, because every time I had Items the dropdown width takes the size of the longest item(or string);
我目前正在处理 C# WPF 项目,我似乎无法做的一件事是 - 如何更改 ComboBox 下拉宽度,因为每次我有项目时,下拉宽度都会采用最长项目(或字符串)的大小;
How can I fix this Please Help fellow developers/programmers !!!!
我该如何解决这个问题请帮助开发人员/程序员!!!!
回答by ELH
Set the ItemContainerStyle of the ComboBoxItem like this:
像这样设置 ComboBoxItem 的 ItemContainerStyle:
<ComboBox Width="50" Height="40">
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Setter Property="Width" Value="60"/>
</Style>
</ComboBox.ItemContainerStyle>
<ComboBoxItem Content="this is Item One "/>
<ComboBoxItem Content="this is Item "/>
<ComboBoxItem Content="this is "/>
<ComboBoxItem Content="this "/>
</ComboBox>

