private static void OnLoadDetectionChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs ev)
        {
            if ((dpo is TextBlock t) &&
                t.Name == MarkupExtensionParser.MarkupParserHelperId)
            {
                return;
            }

            if ((bool)ev.NewValue == true)
            {
                if (dpo is FrameworkElement frameworkElement)
                {
                    frameworkElement.Loaded      += LoadedEventHandler;
                    frameworkElement.Unloaded    += UnloadedEventHandler;
                    frameworkElement.Initialized += FrameworkElement_Initialized;
                    if (frameworkElement.IsLoaded)
                    {
                        LoadedEventHandler.Invoke(frameworkElement, new RoutedEventArgs());
                    }
                }
                else if (dpo is FrameworkContentElement frameworkContentElement)
                {
                    frameworkContentElement.Loaded      += LoadedEventHandler;
                    frameworkContentElement.Unloaded    += UnloadedEventHandler;
                    frameworkContentElement.Initialized += FrameworkElement_Initialized;
                    if (frameworkContentElement.IsLoaded)
                    {
                        LoadedEventHandler.Invoke(frameworkContentElement, new RoutedEventArgs());
                    }
                }
            }
            else
            {
                if (dpo is FrameworkElement frameworkElement)
                {
                    frameworkElement.Unloaded    -= UnloadedEventHandler;
                    frameworkElement.Loaded      -= LoadedEventHandler;
                    frameworkElement.Initialized -= FrameworkElement_Initialized;
                }
                else if (dpo is FrameworkContentElement frameworkContentElement)
                {
                    frameworkContentElement.Unloaded    -= UnloadedEventHandler;
                    frameworkContentElement.Loaded      -= LoadedEventHandler;
                    frameworkContentElement.Initialized -= FrameworkElement_Initialized;
                }
            }
        }
Exemplo n.º 2
0
 private static void OnLoadDetectionChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs ev)
 {
     if ((bool)ev.NewValue == true)
     {
         if (dpo is FrameworkElement frameworkElement)
         {
             frameworkElement.Loaded   += LoadedEventHandler;
             frameworkElement.Unloaded += UnloadedEventHandler;
             //frameworkElement.Initialized += FrameworkElement_Initialized;
             if (frameworkElement.IsLoaded)
             {
                 LoadedEventHandler.Invoke(frameworkElement, new RoutedEventArgs());
             }
         }
         else if (dpo is FrameworkContentElement frameworkContentElement)
         {
             frameworkContentElement.Loaded   += LoadedEventHandler;
             frameworkContentElement.Unloaded += UnloadedEventHandler;
             //frameworkContentElement.Initialized += FrameworkElement_Initialized;
             if (frameworkContentElement.IsLoaded)
             {
                 LoadedEventHandler.Invoke(frameworkContentElement, new RoutedEventArgs());
             }
         }
     }
     else
     {
         if (dpo is FrameworkElement frameworkElement)
         {
             frameworkElement.Unloaded    -= UnloadedEventHandler;
             frameworkElement.Loaded      -= LoadedEventHandler;
             frameworkElement.Initialized -= FrameworkElement_Initialized;
         }
         else if (dpo is FrameworkContentElement frameworkContentElement)
         {
             frameworkContentElement.Unloaded    -= UnloadedEventHandler;
             frameworkContentElement.Loaded      -= LoadedEventHandler;
             frameworkContentElement.Initialized -= FrameworkElement_Initialized;
         }
     }
 }