internal static void InvalidateOnInheritablePropertyChange(FrameworkElement fe, InheritablePropertyChangeInfo info) { if (HasChildren(fe)) { DescendentsWalker <InheritablePropertyChangeInfo> walker = new DescendentsWalker <InheritablePropertyChangeInfo>( TreeWalkPriority.LogicalTree, InheritablePropertyChangeDelegate, info); walker.StartWalk(fe, true); } }
internal static void InvalidateOnInheritablePropertyChange(FrameworkElement fe, InheritablePropertyChangeInfo info) { if (fe.HasLogicalChildren || (fe.INTERNAL_VisualChildrenInformation != null && fe.INTERNAL_VisualChildrenInformation.Count > 0)) { DescendentsWalker <InheritablePropertyChangeInfo> walker = new DescendentsWalker <InheritablePropertyChangeInfo>( TreeWalkPriority.LogicalTree, InheritablePropertyChangeDelegate, info); walker.StartWalk(fe, true); } #if false if (rootFE != null) { if (rootFE.HasLogicalChildren) { rootFE.IsLogicalChildrenIterationInProgress = true; try { IEnumerator logicalChildren = rootFE.LogicalChildren; if (logicalChildren != null) { while (logicalChildren.MoveNext()) { DependencyObject child = logicalChildren.Current as DependencyObject; if (child != null) { child.SetInheritedValue(info.Property, info.NewValue, true); } } } } finally { rootFE.IsLogicalChildrenIterationInProgress = false; } } } if (rootUIE != null) { if (rootUIE.INTERNAL_VisualChildrenInformation != null) { foreach (UIElement child in rootUIE.INTERNAL_VisualChildrenInformation.Keys) { child.SetInheritedValue(info.Property, info.NewValue, true); } } } #endif // false }
/// <summary> /// </summary> internal static void InvalidateOnInheritablePropertyChange( FrameworkElement fe, FrameworkContentElement fce, InheritablePropertyChangeInfo info, bool skipStartNode) { DependencyProperty dp = info.Property; FrameworkObject fo = new FrameworkObject(fe, fce); Debug.Assert(fo.IsValid, "Node with the resources change notification must be an FE or an FCE."); if (HasChildren(fe, fce)) { // Spin up a DescendentsWalker only when // the current node has children to walk DependencyObject d = fo.DO; DescendentsWalker<InheritablePropertyChangeInfo> walker = new DescendentsWalker<InheritablePropertyChangeInfo>( TreeWalkPriority.LogicalTree, InheritablePropertyChangeDelegate, info); walker.StartWalk(d, skipStartNode); } else if (!skipStartNode) { // Degenerate case when the current node is a leaf node and has no children. // If the current node needs a notification, do so now. OnInheritablePropertyChanged(fo.DO, info); } }
/// <summary> /// Invalidates all the properties on the nodes in the given sub-tree /// that are referring to the resource[s] that are changing. /// </summary> internal static void InvalidateOnResourcesChange( FrameworkElement fe, FrameworkContentElement fce, ResourcesChangeInfo info) { Debug.Assert(fe != null || fce != null, "Node with the resources change notification must be an FE or an FCE."); // We're interested in changes to the Template property that occur during // the walk - if the template has changed we don't need to invalidate // template-driven properties a second time. The HasTemplateChanged property // is cleared on the first visit to each node, so that it means "template // changed during the walk". But one relevant node isn't visited during // the walk - the templated parent of the initial node. So we handle that now. FrameworkObject fo = new FrameworkObject(fe, fce); fo.Reset(fo.TemplatedParent); fo.HasTemplateChanged = false; DependencyObject d = (fe != null) ? (DependencyObject)fe : (DependencyObject)fce; if (HasChildren(fe, fce)) { // Spin up a DescendentsWalker only when // the current node has children to walk DescendentsWalker<ResourcesChangeInfo> walker = new DescendentsWalker<ResourcesChangeInfo>( TreeWalkPriority.LogicalTree, ResourcesChangeDelegate, info); walker.StartWalk(d); } else { // Degenerate case when the current node is a leaf node and has no children. OnResourcesChanged(d, info, true); } }
/// <summary> /// Broadcast the Loaded/Unloaded event in the sub-tree starting at the given root /// </summary> /// <param name="root"> /// Root of the sub-tree that the event will be broadcast to /// </param> /// <param name="routedEvent"> /// RoutedEventID for the event we wish to broadcast /// </param> private static void BroadcastEvent(DependencyObject root, RoutedEvent routedEvent) { // Broadcast to the tree and collect the set of nodes // on which we need fire the Loaded event List<DependencyObject> eventRoute = new List<DependencyObject>(); // Create a DescendentsWalker for the broadcast DescendentsWalker<BroadcastEventData> walker = new DescendentsWalker<BroadcastEventData>( TreeWalkPriority.VisualTree, BroadcastDelegate, new BroadcastEventData(root, routedEvent, eventRoute)); // Start the walk down walker.StartWalk(root); // Iterate and raise the event on each of the nodes in the tree for (int i=0; i< eventRoute.Count; i++) { DependencyObject d = eventRoute[i]; RoutedEventArgs args = new RoutedEventArgs(routedEvent, d); FrameworkObject fo = new FrameworkObject(d, true /*throwIfNeither*/); if (routedEvent == FrameworkElement.LoadedEvent) { fo.OnLoaded(args); } else { fo.OnUnloaded(args); } } }
/// <summary> /// get the AttachedAnnotations that are attached on or beneath subtree rooted at element /// this never returns null /// </summary> /// <param name="element">root of subtree</param> /// <returns>list of all attached annotations found. it never returns null.</returns> private IList GetAllAttachedAnnotationsFor(DependencyObject element) { Invariant.Assert(element != null, "Parameter 'element' is null."); List<IAttachedAnnotation> result = new List<IAttachedAnnotation>(); DescendentsWalker<List<IAttachedAnnotation>> walker = new DescendentsWalker<List<IAttachedAnnotation>>(TreeWalkPriority.VisualTree, GetAttachedAnnotationsFor, result); walker.StartWalk(element); return result; }
/// <summary> /// Verify that no other annotation services are attached above, on or below root /// </summary> /// <param name="root">the proposed root for a new AnnotationService being enabled</param> /// <exception cref="InvalidOperationException">Other Instance of AnnotationService Is Already Set</exception> static private void VerifyServiceConfiguration(DependencyObject root) { Invariant.Assert(root != null, "Parameter 'root' is null."); // First make sure there isn't a service above us if (AnnotationService.GetService(root) != null) throw new InvalidOperationException(SR.Get(SRID.AnnotationServiceAlreadyExists)); // Now check the tree below us for an existing service DescendentsWalker<Object> walker = new DescendentsWalker<Object>(TreeWalkPriority.VisualTree, VerifyNoServiceOnNode, null); walker.StartWalk(root); }