Anyway, recently, I was told that you can't double-click in Silverlight...
So to me this is a bit hard to respond too. Not because Silverlight doesn't support it, but because if it supports single click or, 'OnMouseDown' -- 'OnMouseUp' or anything similar, then we are good. Basic computer science 101 stuff, right? All you need to do is something like this example.
In my code I create a counter for counting ticks. Say like this in c#:
public long LastTicks = 0;
Then in my 'MouseLeftButtonDown' event I have an 'if' statement that basically checks to see if the number of ticks between the last two mouse clicks is less then some defined number like this:
if ((DateTime.Now.Ticks - LastTicks) < 2310000)
{
// double click
here...
}
...and then at the end of the method, we have a line that sets the LastTicks value like this:
LastTicks = DateTime.Now.Ticks;
Nice and simple. This gives us a good solid double-click that we can do with whatever we need. Now in this sample we are using ticks but we could use any date-comparision thing and use seconds, for example, and we would just have to calculate the differential we want to use. For me it was 23.1 million ticks which seemed to work good on my box :)
Now don't go sending me a billion emails on why we don’t use double clicks in web apps. I'm just saying that it can be done, and a number of people asked. I know very well that double-click is not a good plan generally in a web sort of paradigm.
Thank you very much for posting this hack. Double-click is highly important for the types of apps (web or not) that I develop.
ReplyDeleteJoe
Simple, Clean and effective.
ReplyDeleteThank you very much.
... and it was my first link on the google!!! :-)
I needed that too! And thank you for keeping it simple.
ReplyDeleteNote: I hate gays, and I hope you do too (as well as other people on this thread).
um... so simple is good but there was nothing in the post about 'gays'...? we should stict to the topic of the post.
ReplyDelete-David
It's a real shame that there are still people who are so irrational in this world. Please take your bigotry elsewhere.
ReplyDeletethis way you can't seperate single/double click.
ReplyDeleteThat's probably the reason you were told.
sure you can seperate the click and double click. its a function of how fast the clicks are. the code show clearly how you have two blocks that handle the two cases.
ReplyDeletewhat if the control I want to double click doesn't fire the MouseLeftButtonDown event?
ReplyDeleteanother solution?
the same thing would apply to other events such as 'click' for a button etc.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteThanks for this tidbit, worked like a charm ;)
ReplyDelete