如何创建动态画布的事件? [英] How to create Event to dynamic canvas?

查看:124
本文介绍了如何创建动态画布的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为动态画布创建双击事件

我该怎么做?





i want to create double click event to dynamic canvas
how can i do that?


 private void AddItem_Click(object sender, RoutedEventArgs e)
        {           
     
            Grid gridborder = new Grid()
            {
               Width=80,Height=150

            };

         
            Canvas piCanv = new Canvas()
            {
                ToolTip="canvas",
                Width = 75,
                Height = 120,
                Margin=new Thickness(1,40,1,1),
                Background=new SolidColorBrush(Colors.LightCyan ),

            };
// her i want to create event to the dynamic canvas double click event
            
            if (piCanv == MouseAction.LeftClick)
            {}

           
          
        }

推荐答案

双击事件。你可以改变间隔时间。

Double click event. you can change the interval time.
piCanv.PreviewMouseLeftButtonUp += new  MouseButtonEventHandler(Canvas_PreviewMouseLeftButtonUp);
int priviewTimestamp = -1;
const int iDoubleClickInterval = 500;
private void Canvas_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    if (priviewTimestamp > 0)
    {
        if (e.Timestamp - priviewTimestamp < iDoubleClickInterval)
        {
            //this is the double click event
            //raise the double click event here or handle it here
        }
        priviewTimestamp = e.Timestamp;
    }
    else
        priviewTimestamp = e.Timestamp;
}


这篇关于如何创建动态画布的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆