zoukankan      html  css  js  c++  java
  • winrt反射

    第一步引用扩展类。

    using System.Reflection.IntrospectionExtensions;

    第二步反射。

    gridView是我定义的GridView控件。ItemClick是它的ItemClick事件。

    var typeInfo = (gridView.GetType()).GetTypeInfo();
                var eventInfo = typeInfo.GetDeclaredEvent("ItemClick");

      

    注意它只能获取自己定的事件,父类定义的要用循环获取。

    EventInfo eventInfo;

    do

    {
                        var typeInfo = type.GetTypeInfo();

           eventInfo = typeInfo.GetDeclaredEvent(eventName);
                        type = typeInfo.BaseType;
                    }
                    while (eventInfo == null && type != null);

    这样就可以获取了。

     //事件替换

    var eventRaisedMethod = this.GetType().GetTypeInfo().GetDeclaredMethod("OnEventRaised");
                    return eventRaisedMethod.CreateDelegate(eventInfo.EventHandlerType, this);

  • 相关阅读:
    MySQL库表设计小技巧
    教你用SQL实现统计排名
    Truncate用法详解
    utf8字符集下的比较规则
    关于Aborted connection告警日志的分析
    MySQL DDL详情揭露
    时间戳,这样用就对了
    在线修改主从复制选项
    20181211HW
    20181207hw
  • 原文地址:https://www.cnblogs.com/wangjinming/p/3683562.html
Copyright © 2011-2022 走看看