zoukankan      html  css  js  c++  java
  • silverlight MouseLeftButtonDown事件无法触发

    在给一个GridView控件添加MouseLeftButtonDown和MouseRightButtonDown事件时,MouseLeftButtonDown事件触发触发不了。

    参考:http://www.cnblogs.com/tianguook/archive/2011/05/13/2045299.html

    原因如下:

      控件在捕获了MouseLeftButtonDown事件后,会将该事件的“Handled”设置为“True”。而在在事件路由中,当某个控件得到一个RoutedEvent,会检测Handled属性,当Handled属性为True时,则忽略该事件。

    解决办法:

          用UIElement.AddHandler 方法 (RoutedEvent, Delegate, Boolean) 。该方法中有一参数handledEventsToo ,类型System.Boolean,如果该参数为True,即使路由事件在其事件数据中标记为已处理(Handled 为 True),也会调用事件处理程序。如果为False,标记为已处理(Handled 为 True),不会再调用事件处理程序,默认为False。

         private void grdCamera_RowLoaded(object sender, RowLoadedEventArgs e)
            {
                GridViewRowItem rowItem = e.Row as GridViewRowItem;
                if (rowItem != null)
                {
                    //给Grid的行绑定右键单击事件
                    rowItem.MouseRightButtonDown += new MouseButtonEventHandler((ss, ee) =>
                    {
                        GridViewRowItem item = ss as GridViewRowItem;
                        if (item != null && item.Item != null)
                        {
                            //选中当前行
                            item.IsSelected = true;
                        }
                    });
                    //给Grid的行绑定左击键单击事件
                    rowItem.AddHandler(GridViewRowItem.MouseLeftButtonDownEvent, new MouseButtonEventHandler(this.rowItem_MouseLeftButtonDown), true);
                }
            }
    
            void rowItem_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                GridViewRowItem item = sender as GridViewRowItem;
                if (item != null && item.Item != null)
                {
                    //empty
                }
            }

     

  • 相关阅读:
    HttpClient后台post 请求webapi
    [SQL Server] 复制数据库任务
    C# js 在页面能执行,放在单独js文件不能执行
    Flink 中的kafka何时commit?
    jar依赖
    AI重要算法
    NonWindowJoin
    Rocket MQ 源码解析
    linear algebra
    Theories of Deep Learning
  • 原文地址:https://www.cnblogs.com/mygod/p/2763470.html
Copyright © 2011-2022 走看看