ComboBox
inherits the Click
event (left mouse button) from Control
. I need to draw a drop-down menu by clicking the right key. How to make it easier without creating a user control inherited from Control
?
- Do you need a contest menu? If yes, then TextBox has a ContextMenu property, perhaps this is what you need. - Serafim Prozorov
- What is the context menu? ComboBox is the same box with a built-in drop-down list! It opens when you click the left mouse button. And I need to make the right one. - AVM
- Oh, sorry, for some reason I read Textbox. - Serafim Prozorov
- It should immediately indicate the correct tags. - andreycha
|
2 answers
You can use the MouseRightButtonUp
event. If necessary, you can additionally calculate what clicked exactly on the button with the arrow.
To prohibit the opening of the list is clearly impossible. You can only close it immediately after opening.
Code behind:
private bool _shouldOpenDropDown; public MainWindow() { InitializeComponent(); comboBox.DropDownOpened += ComboBox_DropDownOpened; comboBox.MouseRightButtonUp += ComboBox_MouseRightButtonUp; } private void ComboBox_DropDownOpened(object sender, EventArgs e) { if (_shouldOpenDropDown) { _shouldOpenDropDown = false; } else { comboBox.IsDropDownOpen = false; } } private void ComboBox_MouseRightButtonUp(object sender, MouseButtonEventArgs e) { _shouldOpenDropDown = true; comboBox.IsDropDownOpen = true; }
- I tried this, but DroppedDown does not have such a property ... - AVM
- By the way, I clarify, I have a WPF application. - AVM
- @AVM updated the answer. - andreycha
- I will try this ... - AVM
- No, it does not help ((( - AVM
|
Use the IsDropDownOpen property of the СomboBox control to manage the drop-down list.
Try this:
public MainWindow() { InitializeComponent(); comboBox.MouseUp += comboBox_MouseUp; } private void comboBox_MouseUp(object sender, MouseButtonEventArgs e) { if(e.RightButton == MouseButtonState.Released) comboBox.IsDropDownOpen = true; }
|