Windows.UI.Xaml.XamlExtensions.OnFirstFrame C# (CSharp) Method

OnFirstFrame() public static method

Waits for a control to render its first frame on screen, then executes the specified action.
public static OnFirstFrame ( this that, Action a ) : void
that this
a Action
return void
        public static void OnFirstFrame(this FrameworkElement that, Action a)
        {
            if (a == null || that == null)
                return;
            #if NETFX_CORE
            EventHandler<object> handler = null;
            #else
            EventHandler handler = null;
            #endif
            RoutedEventHandler unload = null;

            handler = (s, e) =>
            {
                that.LayoutUpdated -= handler;
                that.Unloaded -= unload;

                if (a != null)
                    a.Invoke();
            };
            unload = (s, e) =>
            {
                //clean up to preven leaks if this control is never rendered
                that.LayoutUpdated -= handler;
                that.Unloaded -= unload;

            };
            that.LayoutUpdated += handler;
            that.Unloaded += unload;
        }