WPF:无下拉按钮的ComboBox
问题描述:
我想要一个ComboBox没有下拉按钮,但是当我点击组合框中的文本仍然可以打开。
这是可能与一个WPF组合框吗?
I want a ComboBox which has no dropdown button but can still be opened when I click on the text in the combobox. Is this possible with a WPF combobox?
答
这可能,但你需要retemplate它达到完美。您可以通过覆盖系统参数来获得大部分的方式,如下所示:
It's possible, but you would need to retemplate it to achieve perfection. You can get most of the way there by overriding a system parameter as follows:
<ComboBox>
<ComboBox.Resources>
<sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">0</sys:Double>
</ComboBox.Resources>
<ComboBoxItem>One</ComboBoxItem>
<ComboBoxItem>Two</ComboBoxItem>
<ComboBoxItem>Three</ComboBoxItem>
</ComboBox>
但是,这不是完美的,因为焦点矩形仍然假设有一个下拉按钮。
However, it isn't perfect because the focus rectangle still assumes there is a drop-down button present.