Beispiel #1
0
        internal static void OnVisualChildChanged(DependencyObject parent, DependencyObject child, bool isAdded)
        {
            EventHandler <VisualTreeChangeEventArgs> visualTreeChanged = VisualDiagnostics.s_visualTreeChanged;

            if (visualTreeChanged != null && EnableHelper.IsVisualTreeChangeEnabled)
            {
                int index;
                VisualTreeChangeType changeType;
                if (isAdded)
                {
                    index      = VisualDiagnostics.GetChildIndex(parent, child);
                    changeType = VisualTreeChangeType.Add;
                }
                else
                {
                    // We cannot reliably get correct child index for a removed child. We'll force it to be -1;
                    index      = -1;
                    changeType = VisualTreeChangeType.Remove;
                }

                RaiseVisualTreeChangedEvent(
                    visualTreeChanged,
                    new VisualTreeChangeEventArgs(parent, child, index, changeType),
                    // see EnableHelper.IsChangePermitted
                    isPotentialOuterChange: (changeType == VisualTreeChangeType.Add && index == 0 && VisualTreeHelper.GetParent(parent) == null));
            }
        }
Beispiel #2
0
        internal static void OnVisualChildChanged(DependencyObject parent, DependencyObject child, bool isAdded)
        {
            EventHandler <VisualTreeChangeEventArgs> visualTreeChanged = VisualDiagnostics.s_visualTreeChanged;

            if (visualTreeChanged != null && VisualDiagnostics.IsVisualTreeChangeEnabled)
            {
                int index;
                VisualTreeChangeType changeType;
                if (isAdded)
                {
                    index      = VisualDiagnostics.GetChildIndex(parent, child);
                    changeType = VisualTreeChangeType.Add;
                }
                else
                {
                    // We cannot reliably get correct child index for a removed child. We'll force it to be -1;
                    index      = -1;
                    changeType = VisualTreeChangeType.Remove;
                }
                VisualTreeChangeEventArgs args = new VisualTreeChangeEventArgs(parent, child, index, changeType);
                visualTreeChanged(null, args);
            }
        }