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?
相关问题
- VNC control for WPF application
- How to use Control.FromHandle?
- WPF Binding from System.Windows.SystemParameters.P
- JFX scale image up and down to parent
- Xamarin. The name 'authorEntry does not exist
All WPF controls are "lookless," so you can completely redefine their appearance. However, it's not simple and even less so for ComboBox. ComboBox uses one of two templates, depending on whether it's editable. The non-editable version uses the ToggleButton for the control appearance, so you can just remove the arrow drawing (see below). The editable version uses a TextBox and a ToggleButton, and if you have no ToggleButton, it doesn't open. So here's a template without the ToggleButton; it's up to you to add the code to handle clicks on the editable template. (Or if you don't need to edit, you can just coerce IsEditable to false and be done with it.)
Caveat: This is the Aero template and uses Aero chrome, so it will not display in other themes. For that to happen you would need to pull the templates for each theme and make the appropriate changes or remove the theme chrome and draw your own borders.
Add this namespace definition and add a reference to PresentationFramework.Aero:
Then add the following to your Window/Control Resources:
Then use:
Note: Styles are referenced as
DynamicResource
because they rely on theme chrome so need to respond to changes in the OS visual style. If you remove the chrome and use WPF borders then you should reference these asStaticResource
for performance.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:
However, it isn't perfect because the focus rectangle still assumes there is a drop-down button present.