void HandleActivatable(ILaunchChooser <TResult> handler, object storedClientId) { var activatable = handler as IActivate; EventHandler <ActivationEventArgs> onActivate = null; onActivate = (s, e) => { if (!eventHandled && e.WasInitialized && string.Compare(storedClientId.ToString(), activator.GetKey(handler, string.Empty)) == 0) { handler.Handle(lastResult); lastResult = null; eventHandled = true; } if (activatable != null) { activatable.Activated -= onActivate; } }; if (activatable != null && !activatable.IsActive) { activatable.Activated += onActivate; } else { onActivate(null, new ActivationEventArgs { WasInitialized = true }); } }
void HandleView(object view, object storedClientId, ILaunchChooser <TResult> handler) { var frameworkElement = view as FrameworkElement; RoutedEventHandler onLoaded = null; onLoaded = (s, e) => { if (!eventHandled && string.Compare(storedClientId.ToString(), activator.GetKey(handler, string.Empty)) == 0) { handler.Handle(lastResult); lastResult = null; eventHandled = true; } frameworkElement.Loaded -= onLoaded; }; if (frameworkElement != null) { frameworkElement.Loaded += onLoaded; } else { onLoaded(null, null); } }