如何在 silverlight 中同时处理单击和双击

How to handle both click and double click in silverlight

我想用 silverligh 创建绘画应用程序,但我遇到了问题。我有一个颜色矩形 当单击矩形时,形状将被描边并双击以填充形状。我下面的代码不能正常工作,双击第一个 ClickCount 是 1 然后增加到 2。你能告诉我如何修复它吗?谢谢

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

根据此 post (http://www.c-sharpcorner.com/uploadfile/dbd951/how-to-handle-double-click-in-silverlight-5/),e.ClickCount 具有以下行为。

计数是根据第一次点击和第二次点击之间的时间计算的。 引自 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.

或者您可以考虑具有双击行为,因为我假设您会在绘图应用程序中经常使用它。 这是一篇好文章: 双击框架元素上的 silverlight 事件。 http://blog.cylewitruk.com/2010/10/double-click-event-in-silverlight-on-frameworkelement/

我能想到的第三个选项是使用 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
        }
    });

这是对这个问题的回答:Cleanest single click + double click handling in Silverlight?