public static void ExecuteOnUnload(FrameworkElement element, RoutedEventHandler handler) { #if !XFORMS RoutedEventHandler unloaded = null; unloaded = (s, e) => { element.Unloaded -= unloaded; handler(s, e); }; element.Unloaded += unloaded; #endif }
/// <summary> /// Called after the action is attached to an AssociatedObject. /// </summary> #if WinRT81 protected override void OnAttached() { if (!View.InDesignMode) { Parameters.Attach(AssociatedObject); Parameters.OfType <Parameter>().Apply(x => x.MakeAwareOf(this)); if (View.ExecuteOnLoad(AssociatedObject, ElementLoaded)) { // Not yet sure if this will be needed //var trigger = Interaction.GetTriggers(AssociatedObject) // .FirstOrDefault(t => t.Actions.Contains(this)) as EventTrigger; //if (trigger != null && trigger.EventName == "Loaded") // Invoke(new RoutedEventArgs()); } View.ExecuteOnUnload(AssociatedObject, ElementUnloaded); } base.OnAttached(); }