How do I control the combo box event when I release the mouse cursor on the combo box?(Event is IsMouseDirectlyOverChanged)

Asked 2 years ago, Updated 2 years ago, 72 views

This is a question on wpf(C#).
I would like to close the drop-down of the open combo box when I release the mouse cursor in the combo box, so I don't know how to close the drop-down only for the action pattern with the mouse cursor.

The pattern in question is a pattern in which you click the mouse cursor in the combo box, move it in the same direction as the drop-down, and move it away from the combo box.
If the drop-down is completely down, there is no problem, but if you move it away from the combo box before the drop-down is completely down, the drop-down will close.
This is the only time I want to see it completely without closing the drop-down.

Please tell me how to do that.

The event I am using this time is IsMouseDirectlyOverChanged.

Combo Box Events

Problem Pattern

What I researched was that Google us searched for the "flags that determine whether the drop-down display is incomplete or complete" keyword below.
·combobox dropdown open complete event
·c#Combobox dropdown close soon can click
·combobox dropdown end event
As a result, I didn't get the results I expected.

MainWindow.xaml

<Window:Class="ControlTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns: x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns: mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc —Ignorable="d"
        Title="MainWindow" Height="200" Width="200">
    <Grid>
        <ComboBox IsMouseDirectlyOverChanged="cmb_IsMouseDirectlyOverChanged"
                  Width = "90"
                  Height="30"
                  x —Name = "cmb" >
            <ComboBoxItem>a</ComboBoxItem>
            <ComboBoxItem>b</ComboBoxItem>
            <ComboBoxItem>c</ComboBoxItem>
            <ComboBoxItem>d</ComboBoxItem>
            <ComboBoxItem>e</ComboBoxItem>
            <ComboBoxItem>f</ComboBoxItem>
            <ComboBoxItem>g</ComboBoxItem>
        </ComboBox>
    </Grid>
</Window>

MainWindow.xaml.cs

using System.ComponentModel;
using System.Windows;

namespace ControlTest
{

    public partial class MainWindow—Window
    {

        public MainWindow()
        {
            InitializeComponent();
        }

        // The event "IsMouseDirectlyOverChanged" will allow you to view the
        // Close the drop-down.
        private void cmb_IsMouseDirectlyOverChanged(object sender, DependencyPropertyChangedEventArgse)
        {
            cmb.IsDropDownOpen=false;
        }
    }
}

Problem patterns occur instantaneously.Click to release the mouse almost at the same time.Slow separation results in a problem-free pattern.

c# wpf

2022-09-30 15:42

1 Answers

Basically, I don't recommend putting that kind of control in the combo box, but I thought about what to do if I really want to implement it.

So I thought, how about disabling the combo box animation with the idea of reversal.
With Visual Studio 2022 and .NET6, you could disable it by doing the following:

Property Template

Convert to new resource

Create ControlTemplate Resource

Original PopupAnimation


2022-09-30 15:42

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.