Click here to Skip to main content
11,632,260 members (70,679 online)
Click here to Skip to main content

Tagged as

Mouse Double Click Helper in Silverlight 4.0

, 18 Jul 2012 CPOL 12.8K 3
Rate this:
Please Sign up or sign in to vote.
Custom mouse double click helper class for Silverlight.

Introduction

The code snippet will decide if the user has double clickled on a control or not in Silverlight (or you can use it in anywhere but I will demonstrate it only for Silverlight).

Background

As double click support is not there in Silverlight we have decided to write our own code for the same.

Using the code

TestListBox.MouseLeftButtonDown += new MouseButtonEventHandler(TestListBox_MouseLeftButtonDown);
TestListBox.MouseLeftButtonUp += new MouseButtonEventHandler(TestListBox_MouseLeftButtonUp);

Use the below code for event handling.

/// <summary>
/// Handles the Mouse left button down event
/// </summary>
/// <param name="sender"></param>
/// <param name="arguments"></param>
private void TestListBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs arguments)
{
  try
  {
    arguments.Handled = true;
  }
  catch (Exception exception)
  {
  }
}
/// <summary>
/// Handles Mouse left button up event
/// </summary>
/// <param name="sender"></param>
/// <param name="arguments"></param>
private void TestListBox_MouseLeftButtonUp(object sender, MouseButtonEventArgs arguments)
{
    bool doubleClick;
    try
    {
        doubleClick = MouseDoubleClickHelper.IsDoubleClick(sender, arguments);
        if (doubleClick)
        {      // - Do some work. 
        }
    }
    catch (Exception exception)
    {
    }
}

See attached code for the same. Based on the value of doubleClick variable user can perform any task.

Points of Interest

While writing/analyzing the code I saw that WPF already has a doubleClick event but Silverlight does not. Hope it will be there in the next version. Oh it's there in Silverlight 5 see http://www.silverlight.net/learn/overview/what's-new-in-silverlight-5/silverlight-5-mouse-button-double-and-multi-click.

But we are using Silverlight 4.0 that's really bad. However I think this will be really helpful for those who still use oldies technologies like me.

History

Initial version.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Rahul.KumarSharma
Software Developer (Senior)
India India
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 5 Pin
Christian Amado1-Aug-12 3:23
memberChristian Amado1-Aug-12 3:23 
Questionnot able to download Pin
aashish32122-Jul-12 3:33
memberaashish32122-Jul-12 3:33 
AnswerRe: not able to download Pin
Rahul.KumarSharma29-Jul-12 18:14
memberRahul.KumarSharma29-Jul-12 18:14 
GeneralRe: not able to download Pin
yunkun_yang24-Sep-12 17:12
memberyunkun_yang24-Sep-12 17:12 
GeneralRe: not able to download Pin
forward24-Sep-12 17:13
memberforward24-Sep-12 17:13 
GeneralRe: not able to download Pin
Member 942288028-Sep-12 8:46
memberMember 942288028-Sep-12 8:46 
AnswerRe: not able to download Pin
artyomkr21-Aug-13 12:07
memberartyomkr21-Aug-13 12:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150728.1 | Last Updated 18 Jul 2012
Article Copyright 2012 by Rahul.KumarSharma
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid