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;
}