0

I want to create paint application with silverligh, but I have the problem. I have a color rectangle When click the rectangle the shape will be stroked and double click to fill the shape. My code below not work exactly, when double click the first ClickCount is 1 and then increasing to 2. Can you tell me how to fix it. Thanks.

    private void Rect0_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        if (e.ClickCount == 2)
        {
            RectFront1.Fill = Rect0.Fill;
        }
        else
        {
            RectFront.Fill = Rect0.Fill;
        }
    }

1 Answers1

0

According to this post (http://www.c-sharpcorner.com/uploadfile/dbd951/how-to-handle-double-click-in-silverlight-5/) the e.ClickCount has the following behavior.

The count is calculated based on the time between first click and the second click. Quote from the post.

Consider if you are trying to click 5 times. After 3rd click, if you give 200 milliseconds gab between the 3rd and 4th click then the 4th click will be treated as the 1st click. It will reset the ClickCount property if the time between the first click and second click is greater the 200 milliseconds.

Alternativly you could think about having a behavior for a double click since I assume that you would use it quite often in a paint application. Here is a good article: Double-Click event in silverlight on framework element. http://blog.cylewitruk.com/2010/10/double-click-event-in-silverlight-on-frameworkelement/

The third option I can think of would be using RX (https://www.nuget.org/stats/packages/Rx-Silverlight) https://msdn.microsoft.com/library/hh242985.aspx

Observable.FromEvent<MouseButtonEventArgs>(myControl, "MouseLeftButtonDown").TimeInterval().Subscribe(evt =>
    {
        if (evt.Interval.TotalMilliseconds <= 300)
        {
            // Do something on double click
        }
    });

which was a answer on this question: Cleanest single click + double click handling in Silverlight?

silverfighter
  • 6,762
  • 10
  • 46
  • 73