Silverlight Double Click
February 19, 2009 Leave a comment
Silverlight doesn’t support double clicks as it’s just a by product of the net and is old fashion, well there is a simple way to overcome this, you will just see how simple it actually is.
On the page UserControl we set the following:
private long _lastTicks = 0;
On the object that you want to double click just add the following:
this.Element.MouseLeftButtonDown += new MouseButtonEventHandler(mPlayer_MouseLeftButtonDown);
This puts a single mouse left down event on the object, so how can we use this to our advantage. Ok have a look at our method.
private void mPlayer_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if ((DateTime.Now.Ticks – _lastTicks) < 2310000)
{
// double clicked so do something
}
_lastTicks = DateTime.Now.Ticks;
}
As you can see it’s actually quite simple so enjoy your double click ability in silverlight.