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
                }
            }

     

  • 相关阅读:
    数据结构之链表
    非常好的Java反射例子
    return和finally的执行和联系
    struts2中的OGNL详解
    解耦与耦合的你我他
    struts2案例
    《使用Hibernate开发租房系统》内部测试笔试题
    一对多双向关联关系
    Oracle基本数据类型
    transactionManager的type与dataSource的type
  • 原文地址:https://www.cnblogs.com/mygod/p/2763470.html
Copyright © 2011-2022 走看看