Пример #1
0
        /// <summary>
        /// Waits for the element to load (construct and add to the main object tree).
        /// </summary>
        public static async Task WaitForLoadedAsync(this FrameworkElement frameworkElement)
        {
            if (frameworkElement.IsInVisualTree())
            {
                return;
            }

            await EventAsync.FromRoutedEvent(
                eh => frameworkElement.Loaded += eh,
                eh => frameworkElement.Loaded -= eh);
        }
Пример #2
0
 /// <summary>
 /// Waits for the element to unload (disconnect from the main object tree).
 /// </summary>
 public static async Task WaitForUnloadedAsync(this FrameworkElement frameworkElement)
 {
     await EventAsync.FromRoutedEvent(
         eh => frameworkElement.Unloaded += eh,
         eh => frameworkElement.Unloaded -= eh);
 }