Issues with Multiple Click (ClickCount) in Silverlight 5 Beta

Today we already discussed about Multiple Click (ClickCount) in Silverlight 5 Beta, which was introduced recently. The step-by-step guide focused on how to implement the double click, triple click using the new ClickCount property. In that post we discussed that, there are some issues with this feature and in this post I am going to describe them for you.


Before working with this feature, you must know the pit-falls. This will help you to understand the issue and take care of your code. Read to know more about it.




Before reading further, stop here and ask yourself whether you read my previous post. If not, I will request you to read it first and then come back here again. This will give you the context of the post and will help you to understand the code better.


You can read the previous post here: "Working with Multiple Click (ClickCount) in Silverlight 5 Beta".




Discussion on the Issues

While working with the feature, I noticed some issues which I wanted to share with you. There are two issues. The first one is the raising the event for multiple times and the second one is debugging the event implementation. Let's discuss with them one by one.



Issue #1

If you run our existing sample application that we created while discussing on the feature, you will notice that, for each click, it is actually raising the event with a different count (incremented by 1). If you click once, it will add a single entry "1" in the list; means, it raised the click event for once.


If you click twice (i.e. double click), you will notice that, it first adds "1" and then adds "2"; means, it raises the event two times. Thus making the count changed from one to two.


Similarly, for triple click it raises the same event thrice by incrementing the ClickCount value and adds 3 items in the list. The below screenshot will give you better visibility of the issue:




Like wise, if one clicks more than that; for example if a user clicks very fast for 8 times, it will add 8 items in the ListBox. Because, it will call the event 8 times and each time it will increment the value of the ClickCount. If you stop clicking multiple times for a moment and click once again, you will notice that it resets the counter again and starts from 1. Have a look:




So, what is the problem here? If you imagine the whole coding structure you will better visualize it. For example imagine that, you have a UIElement in one of your game application. There you will have a single click event as well as double click event. Now suppose, for a Single click event you want to show a MessageBox with a message "You clicked once" and for a Double click event you want to show a MessageBox with another message "You double clicked it". You implemented it properly with a proper if{} else{} condition. Everything is fine in code with proper if block. But you will see something different when you run.


For the first case, you will get a proper message for the Single click event. For the second case, you will assume that your code will work and will show a message for double click event. But once you run, you will notice it slightly different. For a double click, it will raise the event two times. First it will go to the single click block and show the message. After that, it will go to the double click block and show the 2nd message. So, in that case it will show 2 different message box and thus break your logic.



Issue #2

This is another problem for the developer. A developer needs to debug his code. He might add two different logic for single click and double click functionality in the same event implementation. Everything is fine up to this. Assume that, the first issue is not a problem here. Put a break point in each if{} block and run your application debug mode.


Once you single click in your UI, it will come to the event and execute the proper if block for the single click event. That's really cool. Now come to the double click event. Try to do a double click. You will notice that, on first click it already got hit to the breakpoint and stopped to that location. Thus gives you no support to click the UI for the second time.


In that case, it is very difficult to debug a double click event. Same is applicable for multiple clicks (more than two).




Yes, that's really a big headache for a developer. Both the two issues will make a developer's life horrible while working with this event. Hope, MSFT will work on these issues before releasing the final product of Silverlight 5. Till then let's see if there are any major issues and/or any workaround.

Kunal Chowdhury
If you have come this far, it means that you liked what you are reading (Issues with Multiple Click (ClickCount) in Silverlight 5 Beta).

Why not reach little more and connect with me directly on Twitter, Facebook, Google+ and LinkedIn. I would love to hear your thoughts and opinions.

Authored Books: