/// <summary> /// Executes the handler immediately if the element is loaded, otherwise wires it to the Loaded event. /// </summary> /// <param name="element">The element.</param> /// <param name="handler">The handler.</param> /// <returns>true if the handler was executed immediately; false otherwise</returns> public static bool ExecuteOnLoad(System.Windows.FrameworkContentElement element, RoutedEventHandler handler) { #if SILVERLIGHT if ((bool)element.GetValue(IsLoadedProperty)) { #elif WinRT if (IsElementLoaded(element)) { #else if (element.IsLoaded) { #endif handler(element, new RoutedEventArgs()); return(true); } RoutedEventHandler loaded = null; loaded = (s, e) => { element.Loaded -= loaded; #if SILVERLIGHT element.SetValue(IsLoadedProperty, true); #endif handler(s, e); }; element.Loaded += loaded; return(false); }
/// <summary> /// Sets the items host. /// </summary> /// <param name="element">The element.</param> private static void SetItemsHost(FrameworkContentElement element) { var parent = element; while (parent.Parent != null) parent = (FrameworkContentElement) parent.Parent; parent.SetValue(ItemsHostProperty, element); }
// =========================================================================== // These methods are invoked when a Style/Template cache needs to be updated // =========================================================================== #region UpdateCache // // This method // 1. Updates the style cache for the given fe/fce // internal static void UpdateStyleCache( FrameworkElement fe, FrameworkContentElement fce, Style oldStyle, Style newStyle, ref Style styleCache) { Debug.Assert(fe != null || fce != null); if (newStyle != null) { // We have a new style. Make sure it's targeting the right // type, and then seal it. DependencyObject d = fe; if (d == null) { d = fce; } newStyle.CheckTargetType(d); newStyle.Seal(); } styleCache = newStyle; // Do style property invalidations. Note that some of the invalidations may be callouts // that could turn around and query the style property on this node. Hence it is essential // to update the style cache before we do this operation. StyleHelper.DoStyleInvalidations(fe, fce, oldStyle, newStyle); // Now look for triggers that might want their EnterActions or ExitActions // to run immediately. StyleHelper.ExecuteOnApplyEnterExitActions(fe, fce, newStyle, StyleDataField); }
/// <summary> /// If you use a bindable flow document element more than once, you may encounter a "Collection was modified" exception. /// The error occurs when the binding is updated because of a change to an inherited dependency property. The most common scenario /// is when the inherited DataContext changes. It appears that an inherited properly like DataContext is propagated to its descendants. /// When the enumeration of descendants gets to a BindableXXX, the dependency properties of that element change according to the new /// DataContext, which change the (non-dependency) properties. However, for some reason, changing the flow content invalidates the /// enumeration and raises an exception. /// To work around this, one can either DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=FrameworkElement}}" /// in code. This is clumsy, so every derived type calls this function instead (which performs the same thing). /// See http://code.logos.com/blog/2008/01/data_binding_in_a_flowdocument.html /// </summary> /// <param name="element"></param> public static void FixupDataContext(FrameworkContentElement element) { Binding b = new Binding(FrameworkContentElement.DataContextProperty.Name); // another approach (if this one has problems) is to bind to an ancestor by ElementName b.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(FrameworkElement), 1); element.SetBinding(FrameworkContentElement.DataContextProperty, b); }
/// <summary> /// Get the logical children for the given FrameworkContentElement /// </summary> public static IEnumerable GetChildren(FrameworkContentElement current) { if (current == null) { throw new ArgumentNullException("current"); } return(new EnumeratorWrapper(current.LogicalChildren)); }
// Token: 0x0600031A RID: 794 RVA: 0x00008CE3 File Offset: 0x00006EE3 private static void UpdateIsLoadedCache(FrameworkContentElement fce, DependencyObject parent) { if (fce.GetValue(FrameworkElement.LoadedPendingProperty) == null) { fce.IsLoadedCache = BroadcastEventHelper.IsLoadedHelper(parent); return; } fce.IsLoadedCache = false; }
/// <summary> /// Given a DependencyObject, see if it's any of the types we know /// to have children. If so, call VisitNode on each of its children. /// </summary> private void IterateChildren(DependencyObject d) { _recursionDepth++; if (FrameworkElement.DType.IsInstanceOfType(d)) { FrameworkElement fe = (FrameworkElement)d; bool hasLogicalChildren = fe.HasLogicalChildren; // FrameworkElement have both a visual and a logical tree. // Sometimes we want to hit Visual first, sometimes Logical. if (_priority == TreeWalkPriority.VisualTree) { WalkFrameworkElementVisualThenLogicalChildren(fe, hasLogicalChildren); } else if (_priority == TreeWalkPriority.LogicalTree) { WalkFrameworkElementLogicalThenVisualChildren(fe, hasLogicalChildren); } else { Debug.Assert(false, "Tree walk priority should be Visual first or Logical first - but this instance of DescendentsWalker has an invalid priority setting that's neither of the two."); } } else if (FrameworkContentElement.DType.IsInstanceOfType(d)) { // FrameworkContentElement only has a logical tree, so we // Walk logical children FrameworkContentElement fce = d as FrameworkContentElement; if (fce.HasLogicalChildren) { WalkLogicalChildren(null, fce, fce.LogicalChildren); } } else { // Neither a FrameworkElement nor FrameworkContentElement. See // if it's a Visual and if so walk the Visual collection Visual v = d as Visual; if (v != null) { WalkVisualChildren(v); } else { Visual3D v3D = d as Visual3D; if (v3D != null) { WalkVisualChildren(v3D); } } } _recursionDepth--; }
// Token: 0x0600076C RID: 1900 RVA: 0x0001732E File Offset: 0x0001552E internal static void RemoveLogicalChild(FrameworkElement parentFE, FrameworkContentElement parentFCE, object child) { if (child != null) { if (parentFE != null) { parentFE.RemoveLogicalChild(child); return; } parentFCE.RemoveLogicalChild(child); } }
// Token: 0x060003C3 RID: 963 RVA: 0x0000ACA8 File Offset: 0x00008EA8 private void WalkFrameworkElementVisualThenLogicalChildren(FrameworkElement feParent, bool hasLogicalChildren) { this.WalkVisualChildren(feParent); List <Popup> value = Popup.RegisteredPopupsField.GetValue(feParent); if (value != null) { foreach (Popup fe in value) { bool visitedViaVisualTree = false; this.VisitNode(fe, visitedViaVisualTree); } } feParent.IsLogicalChildrenIterationInProgress = true; try { if (hasLogicalChildren) { IEnumerator logicalChildren = feParent.LogicalChildren; if (logicalChildren != null) { while (logicalChildren.MoveNext()) { object obj = logicalChildren.Current; FrameworkElement frameworkElement = obj as FrameworkElement; if (frameworkElement != null) { if (VisualTreeHelper.GetParent(frameworkElement) != frameworkElement.Parent) { bool visitedViaVisualTree2 = false; this.VisitNode(frameworkElement, visitedViaVisualTree2); } } else { FrameworkContentElement frameworkContentElement = obj as FrameworkContentElement; if (frameworkContentElement != null) { bool visitedViaVisualTree3 = false; this.VisitNode(frameworkContentElement, visitedViaVisualTree3); } } } } } } finally { feParent.IsLogicalChildrenIterationInProgress = false; } }
internal static void AddLogicalChild(FrameworkElement parentFE, FrameworkContentElement parentFCE, object child) { if (child != null) { if (parentFE != null) { parentFE.AddLogicalChild(child); } else if (parentFCE != null) { parentFCE.AddLogicalChild(child); } } }
// internal FrameworkObject(DependencyObject d, bool throwIfNeither) // : this(d) // { // if (throwIfNeither && this._fe == null && this._fce == null) // { // object arg = (d != null) ? (object)d.GetType() : (object)"NULL"; // throw new InvalidOperationException(System.Windows.SR.Get(SRID.MustBeFrameworkDerived, arg)); // } // } internal FrameworkObject(FrameworkElement frameworkElement, FrameworkContentElement frameworkContentElement) { this.frameworkElement = frameworkElement; this.frameworkContentElement = frameworkContentElement; if (frameworkElement != null) { this.dependencyObject = frameworkElement; } else { this.dependencyObject = frameworkContentElement; } }
// Token: 0x06000C71 RID: 3185 RVA: 0x0002EDAC File Offset: 0x0002CFAC internal static bool IsInheritanceNode(FrameworkContentElement fce, DependencyProperty dp, out InheritanceBehavior inheritanceBehavior) { inheritanceBehavior = InheritanceBehavior.Default; FrameworkPropertyMetadata frameworkPropertyMetadata = dp.GetMetadata(fce.DependencyObjectType) as FrameworkPropertyMetadata; if (frameworkPropertyMetadata != null) { if (fce.InheritanceBehavior != InheritanceBehavior.Default && !frameworkPropertyMetadata.OverridesInheritanceBehavior) { inheritanceBehavior = fce.InheritanceBehavior; } return(frameworkPropertyMetadata.Inherits); } return(false); }
internal static void RemoveLogicalChild(FrameworkElement parentFE, FrameworkContentElement parentFCE, object child) { if (child != null) { Debug.Assert(parentFE != null || parentFCE != null, "Either parentFE or parentFCE should be non-null"); if (parentFE != null) { parentFE.RemoveLogicalChild(child); } else { parentFCE.RemoveLogicalChild(child); } } }
/// <summary> /// Updates the IsLoadedCache on the current FrameworkContentElement /// </summary> private static void UpdateIsLoadedCache( FrameworkContentElement fce, DependencyObject parent) { if (fce.GetValue(FrameworkElement.LoadedPendingProperty) == null) { // Propagate the change to your logical ancestry fce.IsLoadedCache = IsLoadedHelper(parent); } else { // Clear the cache if Loaded is pending fce.IsLoadedCache = false; } }
// Token: 0x0600076D RID: 1901 RVA: 0x00017348 File Offset: 0x00015548 internal static IEnumerator GetLogicalChildren(DependencyObject current) { FrameworkElement frameworkElement = current as FrameworkElement; if (frameworkElement != null) { return(frameworkElement.LogicalChildren); } FrameworkContentElement frameworkContentElement = current as FrameworkContentElement; if (frameworkContentElement != null) { return(frameworkContentElement.LogicalChildren); } return(EmptyEnumerator.Instance); }
public static BlockCollection GetBlockCollection(FrameworkContentElement elem) { if (elem == null) return null; var propInfo = elem.GetType().GetProperty("Blocks"); if (propInfo == null) return null; if (propInfo.CanRead && propInfo.PropertyType==typeof(BlockCollection)) { return propInfo.GetValue(elem, null) as BlockCollection; } if (elem is FlowDocument) return ((FlowDocument)elem).Blocks; if (elem is Section) return ((Section)elem).Blocks; if (elem is ListItem) return ((ListItem)elem).Blocks; if (elem is TableCell) return ((TableCell)elem).Blocks; return null; }
// Token: 0x06000C67 RID: 3175 RVA: 0x0002E60C File Offset: 0x0002C80C internal static void InvalidateOnResourcesChange(FrameworkElement fe, FrameworkContentElement fce, ResourcesChangeInfo info) { FrameworkObject frameworkObject = new FrameworkObject(fe, fce); frameworkObject.Reset(frameworkObject.TemplatedParent); frameworkObject.HasTemplateChanged = false; DependencyObject dependencyObject = (fe != null) ? fe : fce; if (TreeWalkHelper.HasChildren(fe, fce)) { DescendentsWalker <ResourcesChangeInfo> descendentsWalker = new DescendentsWalker <ResourcesChangeInfo>(TreeWalkPriority.LogicalTree, TreeWalkHelper.ResourcesChangeDelegate, info); descendentsWalker.StartWalk(dependencyObject); return; } TreeWalkHelper.OnResourcesChanged(dependencyObject, info, true); }
/// <summary> /// Creates a binding on a <see cref="Parameter"/>. /// </summary> /// <param name="target">The target to which the message is applied.</param> /// <param name="parameter">The parameter object.</param> /// <param name="elementName">The name of the element to bind to.</param> /// <param name="path">The path of the element to bind to.</param> /// <param name="bindingMode">The binding mode to use.</param> public static void BindParameter(System.Windows.FrameworkContentElement target, Parameter parameter, string elementName, string path, BindingMode bindingMode) { var element = elementName == "$this" ? target : BindingScope.GetNamedElements(target).FindName(elementName); if (element == null) { return; } if (string.IsNullOrEmpty(path)) { path = ConventionManager.GetElementConvention(element.GetType()).ParameterProperty; } #if WinRT var binding = new Binding { Path = new PropertyPath(path), Source = element, Mode = bindingMode }; #else var binding = new Binding(path) { Source = element, Mode = bindingMode }; #endif #if (SILVERLIGHT && !SL5) var expression = (BindingExpression)BindingOperations.SetBinding(parameter, Parameter.ValueProperty, binding); var field = element.GetType().GetField(path + "Property", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); if (field == null) { return; } ConventionManager.ApplySilverlightTriggers(element, (DependencyProperty)field.GetValue(null), x => expression, null, null); #else #if !WinRT binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; #endif BindingOperations.SetBinding(parameter, Parameter.ValueProperty, binding); #endif }
// Token: 0x0600076B RID: 1899 RVA: 0x000172F8 File Offset: 0x000154F8 internal static void RemoveLogicalChild(DependencyObject parent, object child) { if (child != null && parent != null) { FrameworkElement frameworkElement = parent as FrameworkElement; if (frameworkElement != null) { frameworkElement.RemoveLogicalChild(child); return; } FrameworkContentElement frameworkContentElement = parent as FrameworkContentElement; if (frameworkContentElement != null) { frameworkContentElement.RemoveLogicalChild(child); } } }
public static DependencyObject GetParent(DependencyObject reference) { System.Windows.FrameworkContentElement frameworkContentElement = reference as System.Windows.FrameworkContentElement; if (frameworkContentElement != null) { return(frameworkContentElement.Parent); } else { FrameworkElement frameworkElement = reference as FrameworkElement; if (frameworkElement != null) { return(frameworkElement.Parent); } } return(null); }
internal static IEnumerator GetLogicalChildren(DependencyObject current) { FrameworkElement fe = current as FrameworkElement; if (fe != null) { return(fe.LogicalChildren); } FrameworkContentElement fce = current as FrameworkContentElement; if (fce != null) { return(fce.LogicalChildren); } return(MS.Internal.Controls.EmptyEnumerator.Instance); }
/// <summary>Attempts to bring the requested UI element into view and raises the <see cref="E:System.Windows.FrameworkElement.RequestBringIntoView" /> event on the target in order to report the results.</summary> /// <param name="current">The UI element to bring into view.</param> // Token: 0x06000768 RID: 1896 RVA: 0x0001726C File Offset: 0x0001546C public static void BringIntoView(DependencyObject current) { if (current == null) { throw new ArgumentNullException("current"); } FrameworkElement frameworkElement = current as FrameworkElement; if (frameworkElement != null) { frameworkElement.BringIntoView(); } FrameworkContentElement frameworkContentElement = current as FrameworkContentElement; if (frameworkContentElement != null) { frameworkContentElement.BringIntoView(); } }
internal static void RemoveLogicalChild(DependencyObject parent, object child) { if (child != null && parent != null) { FrameworkElement parentFE = parent as FrameworkElement; if (parentFE != null) { parentFE.RemoveLogicalChild(child); } else { FrameworkContentElement parentFCE = parent as FrameworkContentElement; if (parentFCE != null) { parentFCE.RemoveLogicalChild(child); } } } }
// Token: 0x060003BF RID: 959 RVA: 0x0000AACC File Offset: 0x00008CCC private void IterateChildren(DependencyObject d) { this._recursionDepth++; if (FrameworkElement.DType.IsInstanceOfType(d)) { FrameworkElement frameworkElement = (FrameworkElement)d; bool hasLogicalChildren = frameworkElement.HasLogicalChildren; if (this._priority == TreeWalkPriority.VisualTree) { this.WalkFrameworkElementVisualThenLogicalChildren(frameworkElement, hasLogicalChildren); } else if (this._priority == TreeWalkPriority.LogicalTree) { this.WalkFrameworkElementLogicalThenVisualChildren(frameworkElement, hasLogicalChildren); } } else if (FrameworkContentElement.DType.IsInstanceOfType(d)) { FrameworkContentElement frameworkContentElement = d as FrameworkContentElement; if (frameworkContentElement.HasLogicalChildren) { this.WalkLogicalChildren(null, frameworkContentElement, frameworkContentElement.LogicalChildren); } } else { Visual visual = d as Visual; if (visual != null) { this.WalkVisualChildren(visual); } else { Visual3D visual3D = d as Visual3D; if (visual3D != null) { this.WalkVisualChildren(visual3D); } } } this._recursionDepth--; }
internal FrameworkObject(DependencyObject d) { // [code should be identical to Reset(d)] this.dependencyObject = d; if (FrameworkElementDType.IsInstanceOfType(d)) { this.frameworkElement = (FrameworkElement)d; this.frameworkContentElement = null; } else if (FrameworkContentElementDType.IsInstanceOfType(d)) { this.frameworkElement = null; this.frameworkContentElement = (FrameworkContentElement)d; } else { this.frameworkElement = null; this.frameworkContentElement = null; } }
/// <summary>Returns the collection of immediate child objects of the specified object, by processing the logical tree.</summary> /// <param name="current">The object from which to start processing the logical tree. This is expected to be either a <see cref="T:System.Windows.FrameworkElement" /> or <see cref="T:System.Windows.FrameworkContentElement" />.</param> /// <returns>The enumerable collection of immediate child objects from the logical tree of the specified object.</returns> // Token: 0x06000765 RID: 1893 RVA: 0x000171E8 File Offset: 0x000153E8 public static IEnumerable GetChildren(DependencyObject current) { if (current == null) { throw new ArgumentNullException("current"); } FrameworkElement frameworkElement = current as FrameworkElement; if (frameworkElement != null) { return(new LogicalTreeHelper.EnumeratorWrapper(frameworkElement.LogicalChildren)); } FrameworkContentElement frameworkContentElement = current as FrameworkContentElement; if (frameworkContentElement != null) { return(new LogicalTreeHelper.EnumeratorWrapper(frameworkContentElement.LogicalChildren)); } return(LogicalTreeHelper.EnumeratorWrapper.Empty); }
/// <summary>Returns the parent object of the specified object by processing the logical tree.</summary> /// <param name="current">The object to find the parent object for. This is expected to be either a <see cref="T:System.Windows.FrameworkElement" /> or a <see cref="T:System.Windows.FrameworkContentElement" />.</param> /// <returns>The requested parent object.</returns> // Token: 0x06000764 RID: 1892 RVA: 0x000171A8 File Offset: 0x000153A8 public static DependencyObject GetParent(DependencyObject current) { if (current == null) { throw new ArgumentNullException("current"); } FrameworkElement frameworkElement = current as FrameworkElement; if (frameworkElement != null) { return(frameworkElement.Parent); } FrameworkContentElement frameworkContentElement = current as FrameworkContentElement; if (frameworkContentElement != null) { return(frameworkContentElement.Parent); } return(null); }
/// <summary> /// Given an enumerator for Logical children, call VisitNode on each /// of the nodes in the enumeration. /// </summary> private void WalkLogicalChildren( FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren) { if (feParent != null) { feParent.IsLogicalChildrenIterationInProgress = true; } else { fceParent.IsLogicalChildrenIterationInProgress = true; } try { if (logicalChildren != null) { while (logicalChildren.MoveNext()) { DependencyObject child = logicalChildren.Current as DependencyObject; if (child != null) { bool visitedViaVisualTree = false; VisitNode(child, visitedViaVisualTree); } } } } finally { if (feParent != null) { feParent.IsLogicalChildrenIterationInProgress = false; } else { fceParent.IsLogicalChildrenIterationInProgress = false; } } }
internal bool WasVisited(DependencyObject d) { DependencyObject ancestor = d; while ((ancestor != _startNode) && (ancestor != null)) { DependencyObject logicalParent; if (FrameworkElement.DType.IsInstanceOfType(ancestor)) { FrameworkElement fe = ancestor as FrameworkElement; logicalParent = fe.Parent; // FrameworkElement DependencyObject dependencyObjectParent = VisualTreeHelper.GetParent(fe); if (dependencyObjectParent != null && logicalParent != null && dependencyObjectParent != logicalParent) { return(_nodes.Contains(ancestor)); } // Follow visual tree if not null otherwise we follow logical tree if (dependencyObjectParent != null) { ancestor = dependencyObjectParent; continue; } } else { // FrameworkContentElement FrameworkContentElement ancestorFCE = ancestor as FrameworkContentElement; logicalParent = (ancestorFCE != null) ? ancestorFCE.Parent : null; } ancestor = logicalParent; } return(ancestor != null); }
public CommonElement(DependencyObject depObj) { _fe = depObj as FrameworkElement; _fce = depObj as FrameworkContentElement; IsValid = _fe != null || _fce != null; }
/// <summary> /// 从FrameworkContentElement,获取<see cref="FrameworkContentElementSprite"/> /// </summary> /// <param name="element">FrameworkContentElement</param> /// <returns></returns> public static ISprite Sprite(this FrameworkContentElement contentElement) { return(FrameworkContentElementSprite.FromElement(contentElement)); }
// Token: 0x06000C74 RID: 3188 RVA: 0x0002EE13 File Offset: 0x0002D013 internal static bool HasChildren(FrameworkElement fe, FrameworkContentElement fce) { return((fe != null && (fe.HasLogicalChildren || fe.HasVisualChildren || Popup.RegisteredPopupsField.GetValue(fe) != null)) || (fce != null && fce.HasLogicalChildren)); }
// Internal method for Parser to find a resource when // the instance is not yet hooked to the logical tree // This method returns DependencyProperty.UnsetValue when // resource is not found. Otherwise it returns the value // found. NOTE: Value resource found could be null // FindResource(fe/fce) Default: dp, unlinkedParent, deferReference, boundaryElement, source, isImplicitStyleLookup internal static object FindResourceInternal(FrameworkElement fe, FrameworkContentElement fce, object resourceKey) { object source; return FindResourceInternal(fe, fce, null, // dp, resourceKey, null, // unlinkedParent, false, // allowDeferredResourceReference, false, // mustReturnDeferredResourceReference, null, // boundaryElement, false, // isImplicitStyleLookup, out source); }
/// <summary> /// Invalidate inheritable properties and resource /// references during a tree change operation. /// </summary> internal static void InvalidateOnTreeChange( FrameworkElement fe, FrameworkContentElement fce, DependencyObject parent, bool isAddOperation) { Debug.Assert(fe != null || fce != null, "Node with the tree change notification must be an FE or an FCE."); Debug.Assert(parent != null, "Must have a parent that the current node is connected to or disconnected from."); // If the tree change is for a non-FE/FCE parent then we need to find // the nearest FE/FCE parent inorder to propagate inheritance correctly. FrameworkObject parentFO = new FrameworkObject(parent); if (!parentFO.IsValid) { parent = parentFO.FrameworkParent.DO; } // 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); // Synchronize the ShouldLookupImplicitStyles flag with respect to the parent here // because for the root node of a tree change UpdateStyleProperty happens right here // in this method. And we need to have synchrnozed the ShouldLookupImplicitStyles // before we re-query the Style property. if (isAddOperation) { fo.SetShouldLookupImplicitStyles(); } fo.Reset(fo.TemplatedParent); fo.HasTemplateChanged = false; DependencyObject d = (fe != null) ? (DependencyObject)fe : (DependencyObject)fce; // during a tree walk to invalidate inherited properties, we typically // call UpdateStyle from FE/FCE.InvalidateTreeDependentProperties. But // for the root element of the tree change, we need to record old values // for inherited properties before we've updated the inheritance parent; // so do the updatestyle here before we record old values so that we // capture any updates provided by styles. if (fe != null) { if (fe.IsInitialized && !fe.HasLocalStyle) { // Clear the HasStyleChanged flag fe.HasStyleChanged = false; fe.HasStyleInvalidated = false; fe.HasTemplateChanged = false; fe.AncestorChangeInProgress = true; fe.UpdateStyleProperty(); fe.AncestorChangeInProgress = false; } } else { if (!fce.HasLocalStyle) { // Clear the HasStyleChanged flag fce.HasStyleChanged = false; fce.HasStyleInvalidated = false; fce.AncestorChangeInProgress = true; fce.UpdateStyleProperty(); fce.AncestorChangeInProgress = false; } } if (HasChildren(fe, fce)) { // Spin up a DescendentsWalker only when // the current node has children to walk // If there is another tree walk that has already visited the // current node then we do not need to re-walk its sub-tree. FrameworkContextData fcdata = FrameworkContextData.From(d.Dispatcher); if (!fcdata.WasNodeVisited(d, TreeChangeDelegate)) { // The TreeChangeInfo object is used here to track // information that we have because we're doing a tree walk. TreeChangeInfo parentInfo = new TreeChangeInfo(d, parent, isAddOperation); // PrePostDescendentsWalker is used instead of the standard // DescendentsWalker because we need a "post" callback to know when // to pop the parent's InheritableProperties cache from the stack. PrePostDescendentsWalker<TreeChangeInfo> walker = new PrePostDescendentsWalker<TreeChangeInfo>( TreeWalkPriority.LogicalTree, TreeChangeDelegate, TreeChangePostDelegate, parentInfo); fcdata.AddWalker(TreeChangeDelegate, walker); try { walker.StartWalk(d); } finally { fcdata.RemoveWalker(TreeChangeDelegate, walker); } } } else { // Degenerate case when the current node is a leaf node and has no children. TreeChangeInfo parentInfo = new TreeChangeInfo(d, parent, isAddOperation); // Degenerate case of OnAncestorChanged for a single node OnAncestorChanged(fe, fce, parentInfo); // Degenerate case of OnPostAncestorChanged for a single node OnPostAncestorChanged(d, parentInfo); } }
public void ClearTags(FrameworkContentElement elem) { elem.Tag = DependencyProperty.UnsetValue; foreach (var e in LogicalTreeHelper.GetChildren(elem).OfType<FrameworkContentElement>()) ClearTags(e); }
// Add Style TargetType and FEF EventHandlers to the EventRoute internal static void AddStyleHandlersToEventRoute( FrameworkElement fe, FrameworkContentElement fce, EventRoute route, RoutedEventArgs args) { Debug.Assert(fe != null || fce != null); DependencyObject source = (fe != null) ? (DependencyObject)fe : (DependencyObject)fce; Style selfStyle = null; FrameworkTemplate selfFrameworkTemplate = null; DependencyObject templatedParent = null; int templateChildIndex = -1; // Fetch selfStyle, TemplatedParent and TemplateChildIndex if (fe != null) { selfStyle = fe.Style; selfFrameworkTemplate = fe.TemplateInternal; templatedParent = fe.TemplatedParent; templateChildIndex = fe.TemplateChildIndex; } else { selfStyle = fce.Style; templatedParent = fce.TemplatedParent; templateChildIndex = fce.TemplateChildIndex; } // Add TargetType EventHandlers to the route. Notice that ThemeStyle // cannot have EventHandlers and hence are ignored here. RoutedEventHandlerInfo[] handlers = null; if (selfStyle != null && selfStyle.EventHandlersStore != null) { handlers = selfStyle.EventHandlersStore.GetRoutedEventHandlers(args.RoutedEvent); AddStyleHandlersToEventRoute(route, source, handlers); } if (selfFrameworkTemplate != null && selfFrameworkTemplate.EventHandlersStore != null) { handlers = selfFrameworkTemplate.EventHandlersStore.GetRoutedEventHandlers(args.RoutedEvent); AddStyleHandlersToEventRoute(route, source, handlers); } if (templatedParent != null) { FrameworkTemplate templatedParentTemplate = null; FrameworkElement feTemplatedParent = templatedParent as FrameworkElement; Debug.Assert( feTemplatedParent != null ); templatedParentTemplate = feTemplatedParent.TemplateInternal; // Fetch handlers from either the parent style or template handlers = null; if (templatedParentTemplate != null && templatedParentTemplate.HasEventDependents) { handlers = StyleHelper.GetChildRoutedEventHandlers(templateChildIndex, args.RoutedEvent, ref templatedParentTemplate.EventDependents); } // Add FEF EventHandlers to the route AddStyleHandlersToEventRoute(route, source, handlers); } }
/// <summary> /// When Style.VisualTree is applied to a FrameworkContentElement, /// it is actually added to the logical tree because FrameworkContentElement /// has no visual tree. /// </summary> /// <remarks> /// A prime example of trying to shove a square peg into a round hole. /// </remarks> internal static void AddNodeToLogicalTree( DependencyObject parent, Type type, bool treeNodeIsFE, FrameworkElement treeNodeFE, FrameworkContentElement treeNodeFCE) { // If the logical parent already has children, then we can't add // a logical subtree from the style, since there would be a conflict. // Throw an exception in this case. FrameworkContentElement logicalParent = parent as FrameworkContentElement; if (logicalParent != null) { IEnumerator childEnumerator = logicalParent.LogicalChildren; if (childEnumerator != null && childEnumerator.MoveNext()) { throw new InvalidOperationException(SR.Get(SRID.AlreadyHasLogicalChildren, parent.GetType().Name)); } } IAddChild addChildParent = parent as IAddChild; if (addChildParent == null) { throw new InvalidOperationException(SR.Get(SRID.CannotHookupFCERoot, type.Name)); } else { if (treeNodeFE != null) { addChildParent.AddChild(treeNodeFE); } else { addChildParent.AddChild(treeNodeFCE); } } }
/// <summary> /// Setup the pointers on this FrameworkElementFactory-created /// node so we can find our way back to the object whose Style /// included this FrameworkElementFactory. /// </summary> private static void NewNodeStyledParentProperty( DependencyObject container, bool isContainerAnFE, bool treeNodeIsFE, FrameworkElement treeNodeFE, FrameworkContentElement treeNodeFCE) { if( treeNodeIsFE ) { treeNodeFE._templatedParent = container ; treeNodeFE.IsTemplatedParentAnFE = isContainerAnFE; } else { treeNodeFCE._templatedParent = container ; treeNodeFCE.IsTemplatedParentAnFE = isContainerAnFE; } }
private static void OnAncestorChanged( FrameworkElement fe, FrameworkContentElement fce, TreeChangeInfo info) { if (fe!= null) { fe.OnAncestorChangedInternal(info); } else { fce.OnAncestorChangedInternal(info); } }
/// <summary> /// Assigns the ElementStyle to the desired property on the given element. /// </summary> internal void ApplyStyle(bool isEditing, bool defaultToElementStyle, FrameworkContentElement element) { Style style = PickStyle(isEditing, defaultToElementStyle); if (style != null) { element.Style = style; } }
/// <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> /// Downcast the given DependencyObject into FrameworkElement or /// FrameworkContentElement, as appropriate. /// </summary> internal static void DowncastToFEorFCE(DependencyObject d, out FrameworkElement fe, out FrameworkContentElement fce, bool throwIfNeither) { if (FrameworkElement.DType.IsInstanceOfType(d)) { fe = (FrameworkElement)d; fce = null; } else if (FrameworkContentElement.DType.IsInstanceOfType(d)) { fe = null; fce = (FrameworkContentElement)d; } else if (throwIfNeither) { throw new InvalidOperationException(SR.Get(SRID.MustBeFrameworkDerived, d.GetType())); } else { fe = null; fce = null; } }
/// <summary> /// Called when all conditions have been satisfied for this action to be /// invoked. (Conditions are not described on this TriggerAction object, /// but on the Trigger object holding it.) /// </summary> /// <remarks> /// This variant is called when the Trigger lives in a Style, and /// hence given a reference to its corresponding Style object. /// </remarks> internal abstract void Invoke( FrameworkElement fe, FrameworkContentElement fce, Style targetStyle, FrameworkTemplate targetTemplate, Int64 layer);
// Token: 0x06000C69 RID: 3177 RVA: 0x0002E674 File Offset: 0x0002C874 internal static void OnResourcesChanged(DependencyObject d, ResourcesChangeInfo info, bool raiseResourceChangedEvent) { bool flag = info.Contains(d.DependencyObjectType.SystemType, true); bool isThemeChange = info.IsThemeChange; bool isStyleResourcesChange = info.IsStyleResourcesChange; bool isTemplateResourcesChange = info.IsTemplateResourcesChange; bool flag2 = info.Container == d; FrameworkObject frameworkObject = new FrameworkObject(d); if (info.IsResourceAddOperation || info.IsCatastrophicDictionaryChange) { frameworkObject.SetShouldLookupImplicitStyles(); } if (frameworkObject.IsFE) { FrameworkElement fe = frameworkObject.FE; fe.HasStyleChanged = false; fe.HasStyleInvalidated = false; fe.HasTemplateChanged = false; if (info.IsImplicitDataTemplateChange) { ContentPresenter contentPresenter = fe as ContentPresenter; if (contentPresenter != null) { contentPresenter.ReevaluateTemplate(); } } if (fe.HasResourceReference) { TreeWalkHelper.InvalidateResourceReferences(fe, info); if ((!isStyleResourcesChange && !isTemplateResourcesChange) || !flag2) { TreeWalkHelper.InvalidateStyleAndReferences(d, info, flag); } } else if (flag && (fe.HasImplicitStyleFromResources || fe.Style == FrameworkElement.StyleProperty.GetMetadata(fe.DependencyObjectType).DefaultValue) && (!isStyleResourcesChange || !flag2)) { fe.UpdateStyleProperty(); } if (isThemeChange) { fe.UpdateThemeStyleProperty(); } if (raiseResourceChangedEvent && fe.PotentiallyHasMentees) { fe.RaiseClrEvent(FrameworkElement.ResourcesChangedKey, new ResourcesChangedEventArgs(info)); return; } } else { FrameworkContentElement fce = frameworkObject.FCE; fce.HasStyleChanged = false; fce.HasStyleInvalidated = false; if (fce.HasResourceReference) { TreeWalkHelper.InvalidateResourceReferences(fce, info); if ((!isStyleResourcesChange && !isTemplateResourcesChange) || !flag2) { TreeWalkHelper.InvalidateStyleAndReferences(d, info, flag); } } else if (flag && (fce.HasImplicitStyleFromResources || fce.Style == FrameworkContentElement.StyleProperty.GetMetadata(fce.DependencyObjectType).DefaultValue) && (!isStyleResourcesChange || !flag2)) { fce.UpdateStyleProperty(); } if (isThemeChange) { fce.UpdateThemeStyleProperty(); } if (raiseResourceChangedEvent && fce.PotentiallyHasMentees) { fce.RaiseClrEvent(FrameworkElement.ResourcesChangedKey, new ResourcesChangedEventArgs(info)); } } }
public static void RemoveSections(FrameworkContentElement elem) { var blocks = GetBlockCollection(elem); if (blocks!=null) foreach (var b in new List<Block>(blocks)) RemoveSections(b); if (elem is Section) { var sec = elem as Section; var parentBlocks = GetBlockCollection(sec.Parent as FrameworkContentElement); if (parentBlocks==null) return; while (sec.Blocks.Count>0) { var block = sec.Blocks.FirstBlock; sec.Blocks.Remove(block); parentBlocks.InsertBefore(sec, block); } parentBlocks.Remove(sec); } }
internal FrameworkObject(FrameworkElement fe, FrameworkContentElement fce) { _fe = fe; _fce = fce; if (fe != null) _do = fe; else _do = fce; }
// Token: 0x06000C6B RID: 3179 RVA: 0x0002E8E0 File Offset: 0x0002CAE0 private static void InvalidateStyleAndReferences(DependencyObject d, ResourcesChangeInfo info, bool containsTypeOfKey) { FrameworkObject frameworkObject = new FrameworkObject(d); if (frameworkObject.IsFE) { FrameworkElement fe = frameworkObject.FE; if (containsTypeOfKey && !info.IsThemeChange && (fe.HasImplicitStyleFromResources || fe.Style == FrameworkElement.StyleProperty.GetMetadata(fe.DependencyObjectType).DefaultValue)) { fe.UpdateStyleProperty(); } if (fe.Style != null && fe.Style.HasResourceReferences && !fe.HasStyleChanged) { StyleHelper.InvalidateResourceDependents(d, info, ref fe.Style.ResourceDependents, false); } if (fe.TemplateInternal != null && fe.TemplateInternal.HasContainerResourceReferences) { StyleHelper.InvalidateResourceDependents(d, info, ref fe.TemplateInternal.ResourceDependents, false); } if (fe.TemplateChildIndex > 0) { FrameworkElement frameworkElement = (FrameworkElement)fe.TemplatedParent; FrameworkTemplate templateInternal = frameworkElement.TemplateInternal; if (!frameworkElement.HasTemplateChanged && templateInternal.HasChildResourceReferences) { StyleHelper.InvalidateResourceDependentsForChild(frameworkElement, fe, fe.TemplateChildIndex, info, templateInternal); } } if (!info.IsThemeChange) { Style themeStyle = fe.ThemeStyle; if (themeStyle != null && themeStyle.HasResourceReferences && themeStyle != fe.Style) { StyleHelper.InvalidateResourceDependents(d, info, ref themeStyle.ResourceDependents, false); return; } } } else if (frameworkObject.IsFCE) { FrameworkContentElement fce = frameworkObject.FCE; if (containsTypeOfKey && !info.IsThemeChange && (fce.HasImplicitStyleFromResources || fce.Style == FrameworkContentElement.StyleProperty.GetMetadata(fce.DependencyObjectType).DefaultValue)) { fce.UpdateStyleProperty(); } if (fce.Style != null && fce.Style.HasResourceReferences && !fce.HasStyleChanged) { StyleHelper.InvalidateResourceDependents(d, info, ref fce.Style.ResourceDependents, true); } if (fce.TemplateChildIndex > 0) { FrameworkElement frameworkElement2 = (FrameworkElement)fce.TemplatedParent; FrameworkTemplate templateInternal2 = frameworkElement2.TemplateInternal; if (!frameworkElement2.HasTemplateChanged && templateInternal2.HasChildResourceReferences) { StyleHelper.InvalidateResourceDependentsForChild(frameworkElement2, fce, fce.TemplateChildIndex, info, templateInternal2); } } if (!info.IsThemeChange) { Style themeStyle2 = fce.ThemeStyle; if (themeStyle2 != null && themeStyle2.HasResourceReferences && themeStyle2 != fce.Style) { StyleHelper.InvalidateResourceDependents(d, info, ref themeStyle2.ResourceDependents, false); } } } }
/// <summary> /// FrameworkContentElement variant of IsInheritanceNode /// </summary> internal static bool IsInheritanceNode( FrameworkContentElement fce, DependencyProperty dp, out InheritanceBehavior inheritanceBehavior) { // Assume can continue search inheritanceBehavior = InheritanceBehavior.Default; // Get Framework metadata (if exists) FrameworkPropertyMetadata metadata = dp.GetMetadata(fce.DependencyObjectType) as FrameworkPropertyMetadata; // Check for correct type of metadata if (metadata != null) { if (fce.InheritanceBehavior != InheritanceBehavior.Default && !metadata.OverridesInheritanceBehavior) { // Hit a tree boundary inheritanceBehavior = fce.InheritanceBehavior; } // Return true if metadata is marked as inheritable; false otherwise return metadata.Inherits; } // Not framework type metadata return false; }
/// <summary> /// Fill and XML Record with a target xml provider specified /// </summary> /// <param name="sender"></param> /// <param name="supressAppend"></param> /// <param name="targetTag"></param> public static void FillXml(object sender, object resourceSource, bool supressAppend, bool supressFill, string targetTag) { // Construct xml record key string resKey = "XmlRecord"; // Use the parent node of the current data context instead? // Tag will be e.g.: HierarchyLevel_Parent bool useParent = false; bool useGrandparent = false; if (null != targetTag) { if (0 < targetTag.IndexOf('_')) { string[] parts = targetTag.Split('_'); targetTag = parts[0]; if ("Parent".Equals(parts[1], StringComparison.CurrentCultureIgnoreCase)) { useParent = true; } else if ("Grandparent".Equals(parts[1], StringComparison.CurrentCultureIgnoreCase)) { useGrandparent = true; } } resKey += "_" + targetTag; } // Calc the data context and get an xml provider from the record key object controlDataContext = null; XmlDataProvider provider = null; if (sender is Button) { // Data context from control System.Windows.FrameworkElement control = sender as System.Windows.FrameworkElement; controlDataContext = control.DataContext; if (useParent) { controlDataContext = ((XmlNode)controlDataContext).ParentNode; } else if (useGrandparent) { controlDataContext = ((XmlNode)controlDataContext).ParentNode.ParentNode; } // Xml provider from user control System.Windows.FrameworkElement resourceSourceControl = resourceSource as System.Windows.FrameworkElement; provider = resourceSourceControl.Resources[resKey] as XmlDataProvider; } else if (sender is FrameworkElement) { System.Windows.FrameworkElement control = sender as System.Windows.FrameworkElement; provider = control.Resources[resKey] as XmlDataProvider; controlDataContext = control.DataContext; if (useParent) { controlDataContext = ((XmlNode)controlDataContext).ParentNode; } else if (useGrandparent) { controlDataContext = ((XmlNode)controlDataContext).ParentNode.ParentNode; } } else if (sender is FrameworkContentElement) { System.Windows.FrameworkContentElement control = sender as System.Windows.FrameworkContentElement; controlDataContext = control.DataContext; if (useParent) { controlDataContext = ((XmlNode)controlDataContext).ParentNode; } else if (useGrandparent) { controlDataContext = ((XmlNode)controlDataContext).ParentNode.ParentNode; } System.Windows.FrameworkElement resourceSourceControl = resourceSource as System.Windows.FrameworkElement; provider = resourceSourceControl.Resources[resKey] as XmlDataProvider; } if (null != provider) { // Get the data context and apply fill to each element IEnumerable <XmlNode> data = GetXmlDataContext(controlDataContext); // as IEnumerable<XmlNode>; if (null != data && 0 < data.Count()) { foreach (XmlNode node in data) { // Get the fill-record xml XmlNode fillNode = provider.Document.FirstChild; CopyElements(node, fillNode, supressAppend, supressFill); break; } } else { // NO-OP } } }
// Token: 0x06000C6C RID: 3180 RVA: 0x0002EB1C File Offset: 0x0002CD1C internal static void InvalidateOnInheritablePropertyChange(FrameworkElement fe, FrameworkContentElement fce, InheritablePropertyChangeInfo info, bool skipStartNode) { DependencyProperty property = info.Property; FrameworkObject frameworkObject = new FrameworkObject(fe, fce); if (TreeWalkHelper.HasChildren(fe, fce)) { DependencyObject @do = frameworkObject.DO; DescendentsWalker <InheritablePropertyChangeInfo> descendentsWalker = new DescendentsWalker <InheritablePropertyChangeInfo>(TreeWalkPriority.LogicalTree, TreeWalkHelper.InheritablePropertyChangeDelegate, info); descendentsWalker.StartWalk(@do, skipStartNode); return; } if (!skipStartNode) { bool visitedViaVisualTree = false; TreeWalkHelper.OnInheritablePropertyChanged(frameworkObject.DO, info, visitedViaVisualTree); } }
/// <summary> /// Says if the current FE or FCE has visual or logical children /// </summary> internal static bool HasChildren(FrameworkElement fe, FrameworkContentElement fce) { // See if we have logical or visual children, in which case this is a real tree invalidation. return ( (fe != null && (fe.HasLogicalChildren || fe.HasVisualChildren || (Popup.RegisteredPopupsField.GetValue(fe) != null) ) ) || (fce != null && fce.HasLogicalChildren) ); }
// FindImplicitSytle(fce) : Default: unlinkedParent, deferReference internal static object FindImplicitStyleResource(FrameworkContentElement fce, object resourceKey, out object source) { // Do a FindResource call only if someone in the ancestry has // implicit styles. This is a performance optimization. if (fce.ShouldLookupImplicitStyles) { object unlinkedParent = null; bool allowDeferredResourceReference = false; bool mustReturnDeferredResourceReference = false; // Implicit style lookup must stop at the app. bool isImplicitStyleLookup = true; // For non-controls the implicit StyleResource lookup must stop at // the templated parent. Look at task 25606 for further details. DependencyObject boundaryElement = fce.TemplatedParent; object implicitStyle = FindResourceInternal(null, fce, FrameworkContentElement.StyleProperty, resourceKey, unlinkedParent, allowDeferredResourceReference, mustReturnDeferredResourceReference, boundaryElement, isImplicitStyleLookup, out source); // Look at comments on the FE version of this method. // Debug.Assert(!(implicitStyle != DependencyProperty.UnsetValue && fce.ShouldLookupImplicitStyles == false), // "ShouldLookupImplicitStyles is false even while there exists an implicit style in the lookup path. To be precise at source " + source); return implicitStyle; } source = null; return DependencyProperty.UnsetValue; }
/// <summary> /// Invalidate all the properties in the given /// collection of inheritable properties /// </summary> /// <remarks> /// This method is called during an [FE/FCE].OnAncestorChange /// </remarks> internal static FrugalObjectList<DependencyProperty> InvalidateTreeDependentProperties( TreeChangeInfo info, FrameworkElement fe, FrameworkContentElement fce, Style selfStyle, Style selfThemeStyle, ref ChildRecord childRecord, bool isChildRecordValid, bool hasStyleChanged, bool isSelfInheritanceParent) { Debug.Assert(fe != null || fce != null, "Must have non-null current node"); DependencyObject d = fe != null ? (DependencyObject)fe : (DependencyObject)fce; FrameworkObject fo = new FrameworkObject(fe, fce); // Pull up the parent's InheritableProperties cache FrugalObjectList<DependencyProperty> parentInheritableProperties = info.InheritablePropertiesStack.Peek(); // Loop through all cached inheritable // to see if they should be invalidated. int inheritablePropertiesCount = parentInheritableProperties != null ? parentInheritableProperties.Count : 0; FrugalObjectList<DependencyProperty> currentInheritableProperties = null; if (HasChildren(fe, fce)) { currentInheritableProperties = new FrugalObjectList<DependencyProperty>(inheritablePropertiesCount); } info.ResetInheritableValueIndexer(); for (int i = 0; i < inheritablePropertiesCount; i++) { DependencyProperty inheritableProperty = parentInheritableProperties[i]; Debug.Assert(inheritableProperty.IsPotentiallyInherited, "if we got here, it means that this property is inheritable by someone"); PropertyMetadata metadata = inheritableProperty.GetMetadata(d); // Invalidate only properties that are marked as inheritable. // These are the ones that will be affected by an ancestor changes. if (metadata.IsInherited) { FrameworkPropertyMetadata fMetadata = (FrameworkPropertyMetadata)metadata; bool changed = InvalidateTreeDependentProperty(info, d, ref fo, inheritableProperty, fMetadata, selfStyle, selfThemeStyle, ref childRecord, isChildRecordValid, hasStyleChanged, isSelfInheritanceParent); // If a change is detected then add the inheritable property to // the current list so that it can be used to invalidate further children if (changed && currentInheritableProperties != null) { Debug.Assert(!currentInheritableProperties.Contains(inheritableProperty), "InheritableProperties list should not have duplicates"); // Children do not need to inherit properties across a tree boundary // unless the property is set to override this behavior. if (!SkipNow(fo.InheritanceBehavior) || fMetadata.OverridesInheritanceBehavior) { currentInheritableProperties.Add(inheritableProperty); } } } } return currentInheritableProperties; }
/// <summary> /// Call EndInit on the newly-created node to fire the /// "Initialized" event. /// </summary> private static void NewNodeEndInit( bool treeNodeIsFE, FrameworkElement treeNodeFE, FrameworkContentElement treeNodeFCE ) { if( treeNodeIsFE ) { // Mark the beginning of the initialization phase treeNodeFE.EndInit(); } else { // Mark the beginning of the initialization phase treeNodeFCE.EndInit(); } }
/// <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); } }
// Return a reference to the ResourceDictionary attached to the Style of // the given Framework(Content)Element, if such a ResourceDictionary exists. private static ResourceDictionary GetStyleResourceDictionary(FrameworkElement fe, FrameworkContentElement fce) { ResourceDictionary table = null; if (fe != null) { if (fe.Style != null) { table = fe.Style.Resources; } } else if (fce != null) { if (fce.Style != null) { table = fce.Style.Resources; } } return table; }
/// <summary> /// Invoke the SoundPlayer action. /// </summary> internal sealed override void Invoke(FrameworkElement el, FrameworkContentElement ctntEl, Style targetStyle, FrameworkTemplate targetTemplate, Int64 layer) { PlayWhenLoaded(); }
// Return a reference to the ResourceDictionary attached to the Template of // the given Framework(Content)Element, if such a ResourceDictionary exists. private static ResourceDictionary GetTemplateResourceDictionary(FrameworkElement fe, FrameworkContentElement fce) { ResourceDictionary table = null; if (fe != null) { Control control = fe as Control; if (control != null && control.Template != null) { table = control.Template.Resources; } } return table; }
/// <summary> /// Called when all conditions have been satisfied for this action to be /// invoked. (Conditions are not described on this TriggerAction object, /// but on the Trigger object holding it.) /// </summary> /// <remarks> /// This variant is called when the Trigger lives in a Style, and /// hence given a reference to its corresponding Style object. /// </remarks> internal abstract void Invoke(FrameworkElement fe, FrameworkContentElement fce, Style targetStyle, FrameworkTemplate targetTemplate, Int64 layer);
/// <summary> /// Update the chain of FrameworkElementFactory-created nodes. /// </summary> /// <remarks> /// We have two collections of child nodes created from all the /// FrameworkElementFactory in a single Style. Some we "care about" /// because of property values, triggers, etc. Others just needed /// to be created and put in a tree, and we can stop worrying about /// them. The former is 'affectedChildren', the latter is /// 'noChildIndexChildren' so called because the nodes we don't /// care about were not assigned a child index. /// </remarks> private static void UpdateChildChains( string childID, int childIndex, bool treeNodeIsFE, FrameworkElement treeNodeFE, FrameworkContentElement treeNodeFCE, List<DependencyObject> affectedChildren, ref List<DependencyObject> noChildIndexChildren ) { if (childID != null) { // If a child ID exists, then, a valid child index exists as well if( treeNodeIsFE ) { treeNodeFE.TemplateChildIndex = childIndex; } else { treeNodeFCE.TemplateChildIndex = childIndex; } // Add this instance to the child index chain so that it may // be tracked by the style affectedChildren.Add(treeNodeIsFE ? (DependencyObject)treeNodeFE : (DependencyObject)treeNodeFCE); } else { // Child nodes with no _childID (hence no _childIndex) are // tracked on a separate chain that will be appended to the // main chain for cleanup purposes. if (noChildIndexChildren == null) { noChildIndexChildren = new List<DependencyObject>(4); } noChildIndexChildren.Add(treeNodeIsFE ? (DependencyObject)treeNodeFE : (DependencyObject)treeNodeFCE); } }