Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not find DoubleClick in XAML

Tags:

I have a ListView control in XAML. The items are defined by a template control with a TextBlock inside a Grid. Now I want to trigger an action when I double click the TextBlock. To my surprise I find there is no DoubleClick event to hook up ... ! I thought it was just the TextBlock that din't have it, but actually no controls have it. I look for DoubleClick and MouseDoubleClick but they are definitely absent.

I have read suggestions where an EventTrigger is added to a control with Gesture="MouseDoubleClick". It looks promising but in my case the compiler complains and tells me there is no such gesture as a MouseDoubleClick. Same with DoubleClick.

Did the DoubleClick disappear in some version of .Net? I have .Net Framework 4.5 and the project is WPF Application.

Do I have to do stupid workarounds by detecting MouseDown and check the elapsed time since last MouseDown? Sounds like stoneage ...

like image 843
Jakob Lithner Avatar asked Nov 01 '12 07:11

Jakob Lithner


2 Answers

It is always refreshing to formulate your problem! After thinking a while I thought maybe they added a counter to the mouse events instead of having separate events. That seems to be the case!!! The MouseButtonEventArgs has a ClickCount property. When checking for value 2 I detect my DoubleClick!

Still a bit odd though to just kick out the DoubleClick. Even after searching I find no reference as to when and why it disappeared.

like image 91
Jakob Lithner Avatar answered Oct 14 '22 08:10

Jakob Lithner


Just to show the solution Jakob means:

private void img_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed && e.ClickCount == 2)
            {
                //DO SOMETHING
            }
        }
like image 35
X3N0N10 Avatar answered Oct 14 '22 08:10

X3N0N10