// Callback on visiting each node in the descendency during a broadcast event
        private static bool OnBroadcastCallback(DependencyObject d, BroadcastEventData data, bool visitedViaVisualTree)
        {
            DependencyObject        root        = data.Root;
            RoutedEvent             routedEvent = data.RoutedEvent;
            List <DependencyObject> eventRoute  = data.EventRoute;

            if (FrameworkElement.DType.IsInstanceOfType(d))
            {
                // If this is a FrameworkElement
                FrameworkElement fe = (FrameworkElement)d;

                if (fe != root && routedEvent == FrameworkElement.LoadedEvent && fe.UnloadedPending != null)
                {
                    // If there is a pending Unloaded event wait till we've broadcast
                    // that event before we can fire the new Loaded event.

                    fe.FireLoadedOnDescendentsInternal();
                }
                else if (fe != root && routedEvent == FrameworkElement.UnloadedEvent && fe.LoadedPending != null)
                {
                    // If there is a pending Loaded event abort it because we are now
                    // being Unloaded.

                    RemoveLoadedCallback(fe, fe.LoadedPending);
                }
                else
                {
                    if (fe != root)
                    {
                        if (routedEvent == FrameworkElement.LoadedEvent && fe.LoadedPending != null)
                        {
                            // If there is a pending Loaded event abort it because we are now
                            // being Loaded.

                            RemoveLoadedCallback(fe, fe.LoadedPending);
                        }
                        else if (routedEvent == FrameworkElement.UnloadedEvent && fe.UnloadedPending != null)
                        {
                            // If there is a pending Unloaded event abort it because we are now
                            // being Unloaded.

                            RemoveUnloadedCallback(fe, fe.UnloadedPending);
                        }
                    }

                    // If element has handlers fire the event and continue to walk down the tree
                    if (fe.SubtreeHasLoadedChangeHandler)
                    {
                        // We cannot assert this condition here for the following reason.
                        // If the [Un]LoadedHandler is added to the current node after the parent
                        // for this node has been [Un]Loaded but before the current node has been [Un]Loaded
                        // (example: within the [Un]Loaded handler for the parent), then the IsLoaded
                        // cache on the current node has been updated to match that of the parent,
                        // and this Assert will be violated. See BroadcastEventHelper.UpdateHasHandlerFlag
                        // for further description.
                        // Debug.Assert(IsLoaded == [false/true],
                        //     "Element should have been [Un]loaded before it is [Un]Loaded back again");

                        fe.IsLoadedCache = (routedEvent == FrameworkElement.LoadedEvent);

                        eventRoute.Add(fe);

                        // Continue walk down subtree
                        return(true);
                    }
                }
            }
            else
            {
                // If this is a FrameworkContentElement
                FrameworkContentElement fce = (FrameworkContentElement)d;

                if (fce != root && routedEvent == FrameworkElement.LoadedEvent && fce.UnloadedPending != null)
                {
                    // If there is a pending Unloaded event wait till we've broadcast
                    // that event before we can fire the new Loaded event.

                    fce.FireLoadedOnDescendentsInternal();
                }
                else if (fce != root && routedEvent == FrameworkElement.UnloadedEvent && fce.LoadedPending != null)
                {
                    // If there is a pending Loaded event abort it because we are now
                    // being Unloaded.

                    RemoveLoadedCallback(fce, fce.LoadedPending);
                }
                else
                {
                    if (fce != root)
                    {
                        if (routedEvent == FrameworkElement.LoadedEvent && fce.LoadedPending != null)
                        {
                            // If there is a pending Loaded event abort it because we are now
                            // being Loaded.

                            RemoveLoadedCallback(fce, fce.LoadedPending);
                        }
                        else if (routedEvent == FrameworkElement.UnloadedEvent && fce.UnloadedPending != null)
                        {
                            // If there is a pending Unloaded event abort it because we are now
                            // being Unloaded.

                            RemoveUnloadedCallback(fce, fce.UnloadedPending);
                        }
                    }

                    // If element has handlers fire the event and continue to walk down the tree
                    if (fce.SubtreeHasLoadedChangeHandler)
                    {
                        // We cannot assert this condition here for the following reason.
                        // If the [Un]LoadedHandler is added to the current node after the parent
                        // for this node has been [Un]Loaded but before the current node has been [Un]Loaded
                        // (example: within the [Un]Loaded handler for the parent), then the IsLoaded
                        // cache on the current node has been updated to match that of the parent,
                        // and this Assert will be violated. See BroadcastEventHelper.UpdateHasHandlerFlag
                        // for further description.
                        // Debug.Assert(IsLoaded == [false/true],
                        //     "Element should have been [Un]loaded before it is [Un]Loaded back again");

                        fce.IsLoadedCache = (routedEvent == FrameworkElement.LoadedEvent);

                        eventRoute.Add(fce);

                        // Continue walk down subtree
                        return(true);
                    }
                }
            }

            // Stop walk down subtree
            return(false);
        }
        // Token: 0x0600030D RID: 781 RVA: 0x000087B8 File Offset: 0x000069B8
        private static bool OnBroadcastCallback(DependencyObject d, BroadcastEventHelper.BroadcastEventData data, bool visitedViaVisualTree)
        {
            DependencyObject        root        = data.Root;
            RoutedEvent             routedEvent = data.RoutedEvent;
            List <DependencyObject> eventRoute  = data.EventRoute;

            if (FrameworkElement.DType.IsInstanceOfType(d))
            {
                FrameworkElement frameworkElement = (FrameworkElement)d;
                if (frameworkElement != root && routedEvent == FrameworkElement.LoadedEvent && frameworkElement.UnloadedPending != null)
                {
                    frameworkElement.FireLoadedOnDescendentsInternal();
                }
                else if (frameworkElement != root && routedEvent == FrameworkElement.UnloadedEvent && frameworkElement.LoadedPending != null)
                {
                    BroadcastEventHelper.RemoveLoadedCallback(frameworkElement, frameworkElement.LoadedPending);
                }
                else
                {
                    if (frameworkElement != root)
                    {
                        if (routedEvent == FrameworkElement.LoadedEvent && frameworkElement.LoadedPending != null)
                        {
                            BroadcastEventHelper.RemoveLoadedCallback(frameworkElement, frameworkElement.LoadedPending);
                        }
                        else if (routedEvent == FrameworkElement.UnloadedEvent && frameworkElement.UnloadedPending != null)
                        {
                            BroadcastEventHelper.RemoveUnloadedCallback(frameworkElement, frameworkElement.UnloadedPending);
                        }
                    }
                    if (frameworkElement.SubtreeHasLoadedChangeHandler)
                    {
                        frameworkElement.IsLoadedCache = (routedEvent == FrameworkElement.LoadedEvent);
                        eventRoute.Add(frameworkElement);
                        return(true);
                    }
                }
            }
            else
            {
                FrameworkContentElement frameworkContentElement = (FrameworkContentElement)d;
                if (frameworkContentElement != root && routedEvent == FrameworkElement.LoadedEvent && frameworkContentElement.UnloadedPending != null)
                {
                    frameworkContentElement.FireLoadedOnDescendentsInternal();
                }
                else if (frameworkContentElement != root && routedEvent == FrameworkElement.UnloadedEvent && frameworkContentElement.LoadedPending != null)
                {
                    BroadcastEventHelper.RemoveLoadedCallback(frameworkContentElement, frameworkContentElement.LoadedPending);
                }
                else
                {
                    if (frameworkContentElement != root)
                    {
                        if (routedEvent == FrameworkElement.LoadedEvent && frameworkContentElement.LoadedPending != null)
                        {
                            BroadcastEventHelper.RemoveLoadedCallback(frameworkContentElement, frameworkContentElement.LoadedPending);
                        }
                        else if (routedEvent == FrameworkElement.UnloadedEvent && frameworkContentElement.UnloadedPending != null)
                        {
                            BroadcastEventHelper.RemoveUnloadedCallback(frameworkContentElement, frameworkContentElement.UnloadedPending);
                        }
                    }
                    if (frameworkContentElement.SubtreeHasLoadedChangeHandler)
                    {
                        frameworkContentElement.IsLoadedCache = (routedEvent == FrameworkElement.LoadedEvent);
                        eventRoute.Add(frameworkContentElement);
                        return(true);
                    }
                }
            }
            return(false);
        }