Exemplo n.º 1
0
            private static IDisposable WinRTEventBind <THandler>(object sender, EventInfo ei, object handler)
            {
                System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken tk = default(System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken);

                Action <System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken> remove
                    = et =>
                    {
                    ei.RemoveMethod.Invoke(sender, new object[] { et });
                    };

                System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMarshal.AddEventHandler <THandler>(
                    ev =>
                {
                    tk = (System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken)ei.AddMethod.Invoke(sender, new object[] { ev });
                    return(tk);
                },
                    remove,
                    (THandler)handler);

                return(new Disposable(() =>
                {
                    System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMarshal.RemoveEventHandler <THandler>(
                        remove,
                        (THandler)handler);
                }
                                      ));
            }
Exemplo n.º 2
0
 /// <summary>
 /// A helper method that exposed in our System.Private.MCG
 /// contract assembly to access the internal ExtractHandler method
 /// There are other options such as
 /// 1) define another EventRegistrationTokenTable.Extracthandler in
 /// System.Private.MCG assembly. Unfortunately this doesn't work because
 /// compiler sees two EventRegistrationTokenTable classes in two contracts
 /// 2) make a Extracthandler an extention method. This requires having a "using" statement for the
 /// extension methods and doesn't make things easier to understand
 /// </summary>
 public static T ExtractHandler <T>(System.Runtime.InteropServices.WindowsRuntime.EventRegistrationTokenTable <T> table, System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken token) where T : class
 {
     return(table.ExtractHandler(token));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a <see cref="EventRegistrationToken"/> from <see cref="System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken"/>.
 /// </summary>
 /// <param name="args">The <see cref="System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken"/> instance containing the event data.</param>
 /// <returns><see cref="EventRegistrationToken"/></returns>
 public static EventRegistrationToken FromEventRegistrationToken(System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken args)
 {
     return(new EventRegistrationToken(args));
 }
Exemplo n.º 4
0
 public void RemoveEventHandler(System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken token)
 {
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventRegistrationToken"/> class, a
 /// Wpf-enabled wrapper for <see cref="System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken"/>
 /// </summary>
 public EventRegistrationToken(System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken instance)
 {
     this.UwpInstance = instance;
 }