Working with Multiple Click (ClickCount) in Silverlight 5 Beta

Some time you need to know whether your user clicked a control once or double clicked it. Sometime you need to know how many click a user did in the UI control. In this post, you will learn about it.


Silverlight 5 Beta has been announced with newly added feature called ClickCount. It's a property added to the MouseButtonEventArgs. Using this you will be able to find out how many multiple click happened by the user.


Read the complete post to know about the implementation and the issues. Don't forget to provide our feedbacks at the end.




To start with this, you need to set up your development environments first. Here is the prerequisite. Follow them to prepare your development environment and create a sample project:

  1. First you need to install the Silverlight 5 Beta. Follow the steps mentioned in the post.
  2. Create a Silverlight Project by following the steps mentioned in the post. If you are new in Silverlight, this post will help you to create a blank Silverlight project.

Once your development machine is ready, we can start describing the new feature.




Setting up the XAML

Let us design our UI. To do this, we will open the MainPage.xaml file and before doing anything, we will split the LayoutRoot Grid to two different Columns as shown below:




Now we need to add a Border control for our ClickCount demo. We will add MouseLeftButtonDown event to it and will check the click count there. We will also add a ListBox in the 2nd column. ListBox will display the result of click count for our demo.


Find herewith the screenshot for the reference:




Here is our complete XAML code:


<UserControl x:Class="ClickCountDemo.MainPage"
    d:DesignHeight="300" d:DesignWidth="400">
    <Grid x:Name="LayoutRoot" Background="White">
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        <Border Width="200" Height="200"
                Grid.Column="0" Margin="10"
                BorderThickness="1" BorderBrush="Red"
        <ListBox x:Name="clickReport"
                 Grid.Column="1" Margin="10"
                 Width="300" Height="200"/>


Once your XAML is ready, jump to the code behind to write the code to insert the click count to the ListBox.




Playing with the Code

Jump to the code behind now and find the MouseLeftButtonDown event that we registered in the XAML. We will add the implementation now. In the event implementation, add the click count from the MouseButtonEventArgs as the item to the ListBox named "clickReport".


See the screenshot below:





In Silverlight 5, we have the new property named "ClickCount" which returns the no. of click. Using this you can decide how many simultaneous click a user did on a specific control and based on the single, double or triple click, you can take action. This is very helpful in game development but not in normal web application scenario.


Find the complete C# code here for reference:


using System.Windows.Controls;
using System.Windows.Input;
namespace ClickCountDemo
    public partial class MainPage : UserControl
        public MainPage()
        private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            clickReport.Items.Insert(0, e.ClickCount);



Once done, it's time to build the project. If you find any build error, resolve those first.




Seeing it in Action

Let's see how it works in our sample application. Run your project and the XAP will load in the browser window with the following UI on the screen, where it will have a Border control (a small orange color rectangle) at the left part and one Listbox at the right side.




Left side rectangle will listen to the click event and insert the click count to the ListBox as we implemented in our code.




Just click once in the rectangle area and you will see the count added to the ListBox as demonstrated in the above UI screenshot.




Now double clicking on the rectangle area will add count two there. See how it was added to the screen. First it listened a single click and then listened the double click event. Hence 1 and 2 were inserted there.


Same thing you will notice for the triple click event too. This time it will add 1, 2 and 3 in the ListBox.




Clicking more times will have the same behaviour. I guess, you are now familiar with this and you can easily use it in your application. But there are some issues with this. We will discuss them in a new post. Till then enjoy working with Double Click, Triple Click with the help of ClickCount property.

If you have come this far, it means that you liked what you are reading. 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 on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.


  1. Silverlight 5 beta enables support for multi-click input on left using the concept clickcount and right mouse button making it easier to implement for silverlight developers.

  2. How can i get all silverLight 4 Tutorials........?

  3. I don't have a separate category for Silverlight 4. You can get all "Silverlight" posts from here: and all "Silverlight 5" posts from here:


© 2008-2016 - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top