Window Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Thursday, 21 April 2011

Silverlight 5 : Multiple Click Support aka ClickCount

Posted on 11:51 by Unknown

In the last article I spend some time with you in discussing some Text related enhancements for Developers in Silverlight 5. Today I am going to discuss one more feature of Silverlight 5 in this short post.

Requirement : We need a mechanism to identify count of multiple mouse clicks made by user.

Scenario : Some over enthusiast end users,if the transaction/process is not happening then they always hit button/any other UI control with high enthusiasm (or sometimes anger) several amount of time, Some time these unnecessary clicks becomes headache and sometimes it is useful to trigger some business function as well. So there is good side and bad side of this.

What Silverlight 5 is offering to us? : Silverlight 5 bits are now giving support/mechanism to identify Multiple Clicks made by user.

How it does that? : Inside your class MouseButtonEventArgs which is sealed,exposes one public property of type Integer like this :

ClickFunda

This ClickCount property gives us number of hits made by user via Mouse.

Cool..any sample ? : Here you go !

XAML :

<Grid x:Name="LayoutRoot" Background="White">
<TextBlock x:Name="MouseCount" FontSize="20" Margin="5,5,5,5" MouseLeftButtonDown="MouseCount_MouseLeftButtonDown" />   </Grid>

C# :

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
     MouseCount.Text = "This Place will show how many times you play with Mouse !";
}

private void MouseCount_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
           // Checks the number of clicks.
           if (e.ClickCount == 1)
           {
               // Single Click occurred.
               MouseCount.Text = String.Empty;
               MouseCount.Text = "You clicked Mouse Once !";
           }

           if (e.ClickCount == 2)
           {
               // Double Click occurred.
               MouseCount.Text = String.Empty;
               MouseCount.Text = "You clicked Mouse Twice !";
           }

           if (e.ClickCount >= 3)
           {
               // Triple Click occurred.
               MouseCount.Text = String.Empty;
               MouseCount.Text = "You clicked Mouse more than 2 times !";
}}
Remember e.ClickCount is a key ! it will give you number of clicks.

Will it work? : Yes ! Here is the output starting from no click to more than 2 clicks …

ItemClick

ItemClick1

ItemClick2

ItemClick3

Wait ! All that glitters is not Gold !! :

My dear friend and fellow Silverlight MVP Kunal Chowdhury written a quick article on “Issues with Multiple Clicks in Silverlight 5”, so read that here and get to know how this e.ClickCounts make life bit difficult for Developers like you and me.

What’s the Problem ? – Debugging ! :

If you observe the code snippet above and article by Kunal which I shared above,you will find that there is a great trouble to your brain while debugging since despite of e.ClickCount > 1 still it always hits e.ClickCount = 1 condition and comes out of the game and Game is over for us since we really can’t debug and see the stuff for e.ClickCount > 1 and here we see the sad story !

Is it a Bug? what can be done to avoid this ? :

Well, As a MVP I see it as functional issue rather than calling it as Bug since functionality is working but issue is coming only while debugging so I feel little awkward to call it as Bug !

Condition to your Breakpoint is the only option I find it suitable at this particular moment unless someone from Microsoft don’t come up with something better to avoid this debug issue. So if I want to check / debug and see some stuff for e.ClickCount then how will I achieve this? .. well all you need to do is just right click and click on Condition like this :

ItemCondition1

ItemCondition2

ItemCondition3

Above screen shows how easy is our life ! So now be ready to debug all that e.ClickCount > 1 stuff which was giving you trouble earlier. Remember that even for Switch..Case it’s the same issue so don’t be under impression that problem will not occur with Switch..Case.

One you done with adding condition, it will be hitting your breakpoint and executing appropriate condition on basis of e.ClickCount value and you can see that output like this :

ItemCondition4

So this is bit schoolish solution but it works in such tricky conditions and we can survive for the time being.

Well,Take the positive part of this wonderful feature and how it is helpful in real business scenario, I personally still have no clue if this is officially marked as “Bug” or not,but this is what came to my observation when I was playing with the bits, I hope in coming RTW bits something will come up for this, Well enough for today and some more such nice features and funny tricky solutions and scenarios are coming up in my upcoming posts,So stay tuned !

Vikram.

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • First Windows Phone 7 update February 2011 - Small update but Big start
    After tons of rumors and set of predictions on Windows Phone 7 all over Internet, Microsoft came up with first Windows Phone 7 minor update ...
  • The little Story of “I Unlock Joy” event by Microsoft and Pune User Group
      This post is about recent “I Unlock Joy” event happened in Pune which was conducted by Microsoft and Pune User Group. Little History : ...
  • Silverlight On Mobile : Windows Phone 7 Splash Screen and Customization
    After talking about 3D capabilities on Windows Phone 7 using Silverlight in last article , Now I am moving ahead with small but equally impo...
  • Silverlight 5 : Platform Invoke (PInvoke) in Silverlight
      Two days back Microsoft announced availability of Silverlight 5 RC,I encourage you to download bits from here , My friend Pete Brown alr...
  • Introduction to Speech Capabilities in Windows Phone 8 – Part 1
    After a long..I am writing blog, I hope and I wish I will resume blogging like I use to in past. Lots of things happened in past few months....
  • MCTS : Microsoft Silverlight 4 Development Exam Guide (70-506) by Packt Publishing
      Hello, After a long time I got chance to come back here.I will soon resume blogging in month of August. Last 4-5 months were horrible due...
  • Introduction to Speech Capabilities in Windows Phone 8 – Part 2
    Hope you enjoyed my last article on Speech Capability in Windows Phone 8, Today I am posting another part or you can say little extension t...
  • Silverlight 3 : Insert & Update Data using WCF Service with DataForm and DataGrid
    In my Lap around Silverlight 3 series, I have written a separate article on DataForm in Silverlight 3, This article is a basic extension to ...
  • Mango : Using DeviceStatus in Windows Phone 7.1
    First of all “Thank You” for your wonderful response and comments on my last article on Silverlight Vs HTML5 ,I hope you like the points I ...
  • Silverlight, HTML5 & Windows 8 : Where we are heading to ?
    This is not the post or yet another post on most happening debate of Silverlight and HTML5, This is just a visit to all of them to realize t...

Blog Archive

  • ►  2013 (4)
    • ►  August (1)
    • ►  April (3)
  • ►  2012 (4)
    • ►  July (1)
    • ►  March (2)
    • ►  January (1)
  • ▼  2011 (24)
    • ►  December (1)
    • ►  September (4)
    • ►  August (2)
    • ►  July (1)
    • ►  June (4)
    • ►  May (3)
    • ▼  April (3)
      • Silverlight 5 : Multiple Click Support aka ClickCount
      • Silverlight 5 : Improvements in Text
      • Silverlight 5 : A step ahead from Microsoft
    • ►  March (1)
    • ►  February (4)
    • ►  January (1)
  • ►  2010 (21)
    • ►  December (1)
    • ►  November (2)
    • ►  October (3)
    • ►  September (2)
    • ►  August (4)
    • ►  July (5)
    • ►  May (1)
    • ►  April (1)
    • ►  March (1)
    • ►  January (1)
  • ►  2009 (49)
    • ►  December (1)
    • ►  November (5)
    • ►  October (2)
    • ►  September (1)
    • ►  August (5)
    • ►  July (5)
    • ►  June (1)
    • ►  May (5)
    • ►  April (5)
    • ►  March (9)
    • ►  February (4)
    • ►  January (6)
  • ►  2008 (43)
    • ►  December (3)
    • ►  November (9)
    • ►  October (7)
    • ►  September (4)
    • ►  August (2)
    • ►  July (3)
    • ►  June (4)
    • ►  May (3)
    • ►  March (3)
    • ►  February (5)
Powered by Blogger.

About Me

Unknown
View my complete profile