/// <summary> /// You have a new InheritanceContext /// </summary> /// <remarks> /// This is to solve the case of programmatically creating a VisualBrush or BitmapCacheBrush /// with an element in it and the element not getting Initialized. /// </remarks> internal override void AddInheritanceContext(DependencyObject context, DependencyProperty property) { base.AddInheritanceContext(context, property); // Initialize, if not already done TryFireInitialized(); // accept the new inheritance context provided that // a) the requested link uses VisualBrush.Visual or BitmapCacheBrush.TargetProperty // b) this element has no visual or logical parent // c) the context does not introduce a cycle if ((property == VisualBrush.VisualProperty || property == BitmapCacheBrush.TargetProperty) && FrameworkElement.GetFrameworkParent(this) == null //!FrameworkObject.IsEffectiveAncestor(this, context, property)) && !FrameworkObject.IsEffectiveAncestor(this, context)) { //FrameworkObject.Log("+ {0}", FrameworkObject.LogIC(context, property, this)); if (!HasMultipleInheritanceContexts && InheritanceContext == null) { // first request - accept the new inheritance context InheritanceContextField.SetValue(this, context); OnInheritanceContextChanged(EventArgs.Empty); } else if (InheritanceContext != null) { // second request - remove all context and enter "shared" mode InheritanceContextField.ClearValue(this); WriteInternalFlag2(InternalFlags2.HasMultipleInheritanceContexts, true); OnInheritanceContextChanged(EventArgs.Empty); } // else already in shared mode - ignore the request } }
// connect to a new mentor void ConnectMentor(DependencyObject mentor) { FrameworkObject foMentor = new FrameworkObject(mentor); // register for InheritedPropertyChanged events foMentor.InheritedPropertyChanged += new InheritedPropertyChangedEventHandler(OnMentorInheritedPropertyChanged); // register for ResourcesChanged events foMentor.ResourcesChanged += new EventHandler(OnMentorResourcesChanged); // invalidate the mentee's tree TreeWalkHelper.InvalidateOnTreeChange( null, this, foMentor.DO, true /* isAddOperation */ ); // register for Loaded/Unloaded events. // Do this last so the tree is ready when Loaded is raised. if (this.SubtreeHasLoadedChangeHandler) { bool isLoaded = foMentor.IsLoaded; ConnectLoadedEvents(ref foMentor, isLoaded); if (isLoaded) { this.FireLoadedOnDescendentsInternal(); } } }
// protected internal void RemoveLogicalChild(object child) { if (child != null) { // It is invalid to modify the children collection that we // might be iterating during a property invalidation tree walk. if (IsLogicalChildrenIterationInProgress) { throw new InvalidOperationException(SR.Get(SRID.CannotModifyLogicalChildrenDuringTreeWalk)); } // Child is present FrameworkObject fo = new FrameworkObject(child as DependencyObject); if (fo.Parent == this) { fo.ChangeLogicalParent(null); } // This could have been the last child, so check if we have any more children IEnumerator children = LogicalChildren; // if null, there are no children. if (children == null) { HasLogicalChildren = false; } else { // If we can move next, there is at least one child HasLogicalChildren = children.MoveNext(); } } }
/// <summary> /// You are about to provided as the InheritanceContext for the target. /// You can choose to allow this or not. /// </summary> internal override bool ShouldProvideInheritanceContext(DependencyObject target, DependencyProperty property) { // return true if the target is neither a FE or FCE FrameworkObject fo = new FrameworkObject(target); return(!fo.IsValid); }
// Token: 0x06000692 RID: 1682 RVA: 0x00014C34 File Offset: 0x00012E34 private void AddNodeToParent(DependencyObject parent, FrameworkObject childFrameworkObject) { RowDefinition rowDefinition = null; Grid grid; ColumnDefinition columnDefinition; if (childFrameworkObject.IsFCE && (grid = (parent as Grid)) != null && ((columnDefinition = (childFrameworkObject.FCE as ColumnDefinition)) != null || (rowDefinition = (childFrameworkObject.FCE as RowDefinition)) != null)) { if (columnDefinition != null) { grid.ColumnDefinitions.Add(columnDefinition); return; } if (rowDefinition != null) { grid.RowDefinitions.Add(rowDefinition); return; } } else { if (!(parent is IAddChild)) { throw new InvalidOperationException(SR.Get("TypeMustImplementIAddChild", new object[] { parent.GetType().Name })); } ((IAddChild)parent).AddChild(childFrameworkObject.DO); } }
/// <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); } } }
// Token: 0x06000317 RID: 791 RVA: 0x00008AB4 File Offset: 0x00006CB4 private static bool AreThereLoadedChangeHandlersInSubtree(ref FrameworkObject fo) { if (!fo.IsValid) { return(false); } if (fo.ThisHasLoadedChangeEventHandler) { return(true); } if (fo.IsFE) { Visual fe = fo.FE; int childrenCount = VisualTreeHelper.GetChildrenCount(fe); for (int i = 0; i < childrenCount; i++) { FrameworkElement frameworkElement = VisualTreeHelper.GetChild(fe, i) as FrameworkElement; if (frameworkElement != null && frameworkElement.SubtreeHasLoadedChangeHandler) { return(true); } } } foreach (object obj in LogicalTreeHelper.GetChildren(fo.DO)) { DependencyObject dependencyObject = obj as DependencyObject; if (dependencyObject != null && BroadcastEventHelper.SubtreeHasLoadedChangeHandlerHelper(dependencyObject)) { return(true); } } return(false); }
// Token: 0x06000313 RID: 787 RVA: 0x00008A44 File Offset: 0x00006C44 internal static FrameworkElementFactory GetFEFTreeRoot(DependencyObject templatedParent) { FrameworkObject frameworkObject = new FrameworkObject(templatedParent, true); FrameworkTemplate templateInternal = frameworkObject.FE.TemplateInternal; return(templateInternal.VisualTree); }
// disconnect from an old mentor void DisconnectMentor(DependencyObject mentor) { FrameworkObject foMentor = new FrameworkObject(mentor); // unregister for InheritedPropertyChanged events foMentor.InheritedPropertyChanged -= new InheritedPropertyChangedEventHandler(OnMentorInheritedPropertyChanged); // unregister for ResourcesChanged events foMentor.ResourcesChanged -= new EventHandler(OnMentorResourcesChanged); // invalidate the mentee's tree TreeWalkHelper.InvalidateOnTreeChange( null, this, foMentor.DO, false /* isAddOperation */ ); // unregister for Loaded/Unloaded events if (this.SubtreeHasLoadedChangeHandler) { bool isLoaded = foMentor.IsLoaded; DisconnectLoadedEvents(ref foMentor, isLoaded); if (foMentor.IsLoaded) { this.FireUnloadedOnDescendentsInternal(); } } }
// Token: 0x06000C6E RID: 3182 RVA: 0x0002ECD4 File Offset: 0x0002CED4 internal static void OnInheritedPropertyChanged(DependencyObject d, ref InheritablePropertyChangeInfo info, InheritanceBehavior inheritanceBehavior) { if (inheritanceBehavior == InheritanceBehavior.Default || TreeWalkHelper.IsForceInheritedProperty(info.Property)) { FrameworkObject frameworkObject = new FrameworkObject(d); frameworkObject.OnInheritedPropertyChanged(ref info); } }
internal void OnAncestorChangedInternal(TreeChangeInfo parentTreeState) { // Cache the IsSelfInheritanceParent flag bool wasSelfInheritanceParent = IsSelfInheritanceParent; if (parentTreeState.Root != this) { // Clear the HasStyleChanged flag HasStyleChanged = false; HasStyleInvalidated = false; } // If this is a tree add operation update the ShouldLookupImplicitStyles // flag with respect to your parent. if (parentTreeState.IsAddOperation) { FrameworkObject fo = new FrameworkObject(null, this); fo.SetShouldLookupImplicitStyles(); } // Invalidate ResourceReference properties if (HasResourceReference) { // This operation may cause a style change and hence should be done before the call to // InvalidateTreeDependents as it relies on the HasStyleChanged flag TreeWalkHelper.OnResourcesChanged(this, ResourcesChangeInfo.TreeChangeInfo, false); } // If parent is a FrameworkElement // This is also an operation that could change the style FrugalObjectList <DependencyProperty> currentInheritableProperties = InvalidateTreeDependentProperties(parentTreeState, IsSelfInheritanceParent, wasSelfInheritanceParent); // we have inherited properties that changes as a result of the above; // invalidation; push that list of inherited properties on the stack // for the children to use parentTreeState.InheritablePropertiesStack.Push(currentInheritableProperties); // Notify the PresentationSource that this element's ancestry may have changed. // We only need the ContentElement's because UIElements are taken care of // through the Visual class. PresentationSource.OnAncestorChanged(this); // Call OnAncestorChanged OnAncestorChanged(); // Notify mentees if they exist if (PotentiallyHasMentees) { // Raise the ResourcesChanged Event so that ResourceReferenceExpressions // on non-[FE/FCE] listening for this can then update their values RaiseClrEvent(FrameworkElement.ResourcesChangedKey, EventArgs.Empty); } }
/// <summary> /// Check if the Framework Element Factory that produced the Template /// that created this control has a Loaded Change Handler. /// </summary> /// <param name="templatedParent"> /// The caller must pass in a non-null templatedParent. /// </param> internal static FrameworkElementFactory GetFEFTreeRoot(DependencyObject templatedParent) { FrameworkObject fo = new FrameworkObject(templatedParent, true); Debug.Assert(fo.IsFE); FrameworkTemplate templatedParentTemplate = fo.FE.TemplateInternal; FrameworkElementFactory fefTree = templatedParentTemplate.VisualTree; return(fefTree); }
// handle the Unloaded event from the mentor void OnMentorUnloaded(object sender, RoutedEventArgs e) { FrameworkObject foMentor = new FrameworkObject((DependencyObject)sender); // stop listening for Unloaded, start listening for Loaded foMentor.Unloaded -= new RoutedEventHandler(OnMentorUnloaded); foMentor.Loaded += new RoutedEventHandler(OnMentorLoaded); // broadcast the Unloaded event to my framework subtree //FireUnloadedOnDescendentsInternal(); BroadcastEventHelper.BroadcastUnloadedSynchronously(this, IsLoaded); }
// Token: 0x06005CD0 RID: 23760 RVA: 0x001A1E64 File Offset: 0x001A0064 private static object OnCoerceContent(DependencyObject d, object baseValue) { DataGridColumnHeader dataGridColumnHeader = d as DataGridColumnHeader; object coercedTransferPropertyValue = DataGridHelper.GetCoercedTransferPropertyValue(dataGridColumnHeader, baseValue, ContentControl.ContentProperty, dataGridColumnHeader.Column, DataGridColumn.HeaderProperty); FrameworkObject frameworkObject = new FrameworkObject(coercedTransferPropertyValue as DependencyObject); if (frameworkObject.Parent != null && frameworkObject.Parent != dataGridColumnHeader) { frameworkObject.ChangeLogicalParent(null); } return(coercedTransferPropertyValue); }
// Token: 0x06000877 RID: 2167 RVA: 0x0001B9C4 File Offset: 0x00019BC4 internal override void OnAttach(DependencyObject d, DependencyProperty dp) { this._targetObject = d; this._targetProperty = dp; FrameworkObject frameworkObject = new FrameworkObject(this._targetObject); frameworkObject.HasResourceReference = true; if (!frameworkObject.IsValid) { this._targetObject.InheritanceContextChanged += this.InvalidateExpressionValue; } }
void ConnectLoadedEvents(ref FrameworkObject foMentor, bool isLoaded) { if (foMentor.IsValid) { if (isLoaded) { foMentor.Unloaded += new RoutedEventHandler(OnMentorUnloaded); } else { foMentor.Loaded += new RoutedEventHandler(OnMentorLoaded); } } }
// called by BroadcastEventHelper when the SubtreeHasLoadedChangedHandler // flag changes on a mentored FE/FCE internal void ChangeSubtreeHasLoadedChangedHandler(DependencyObject mentor) { FrameworkObject foMentor = new FrameworkObject(mentor); bool isLoaded = foMentor.IsLoaded; if (this.SubtreeHasLoadedChangeHandler) { ConnectLoadedEvents(ref foMentor, isLoaded); } else { DisconnectLoadedEvents(ref foMentor, isLoaded); } }
/// <summary> /// This method causes the ThemeStyleProperty to be re-evaluated /// </summary> internal void UpdateThemeStyleProperty() { if (IsThemeStyleUpdateInProgress == false) { IsThemeStyleUpdateInProgress = true; try { StyleHelper.GetThemeStyle(/* fe = */ this, /* fce = */ null); // Update the ContextMenu and ToolTips separately because they aren't in the tree ContextMenu contextMenu = GetValueEntry( LookupEntry(ContextMenuProperty.GlobalIndex), ContextMenuProperty, null, RequestFlags.DeferredReferences).Value as ContextMenu; if (contextMenu != null) { TreeWalkHelper.InvalidateOnResourcesChange(contextMenu, null, ResourcesChangeInfo.ThemeChangeInfo); } DependencyObject toolTip = GetValueEntry( LookupEntry(ToolTipProperty.GlobalIndex), ToolTipProperty, null, RequestFlags.DeferredReferences).Value as DependencyObject; if (toolTip != null) { FrameworkObject toolTipFO = new FrameworkObject(toolTip); if (toolTipFO.IsValid) { TreeWalkHelper.InvalidateOnResourcesChange(toolTipFO.FE, toolTipFO.FCE, ResourcesChangeInfo.ThemeChangeInfo); } } OnThemeChanged(); } finally { IsThemeStyleUpdateInProgress = false; } } else { throw new InvalidOperationException(SR.Get(SRID.CyclicThemeStyleReferenceDetected, this)); } }
// 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> /// Notification that the ResourceReferenceExpression has been set as a property's value /// </summary> /// <param name="d">DependencyObject being set</param> /// <param name="dp">Property being set</param> internal override void OnAttach(DependencyObject d, DependencyProperty dp) { _targetObject = d; _targetProperty = dp; FrameworkObject fo = new FrameworkObject(_targetObject); fo.HasResourceReference = true; if (!fo.IsValid) { // Listen for the InheritanceContextChanged event on the target node, // so that if this context hierarchy changes we can re-evaluate this expression. _targetObject.InheritanceContextChanged += new EventHandler(InvalidateExpressionValue); } }
private DependencyObject FindAncestorOfType(Type type, int level, DependencyObject d, bool isTracing) { if (type == null) { if (TraceData.IsEnabled) { TraceData.Trace(TraceEventType.Error, TraceData.RefAncestorTypeNotSpecified); } return(null); } if (level < 1) { if (TraceData.IsEnabled) { TraceData.Trace(TraceEventType.Error, TraceData.RefAncestorLevelInvalid); } return(null); } // initialize search to start at the parent of the given DO FrameworkObject fo = new FrameworkObject(d); fo.Reset(fo.GetPreferVisualParent(true).DO); while (fo.DO != null) { if (isTracing) { TraceData.Trace(TraceEventType.Warning, TraceData.AncestorLookup( type.Name, TraceData.Identify(fo.DO))); } if (type.IsInstanceOfType(fo.DO)) // found it! { if (--level <= 0) { break; } } fo.Reset(fo.PreferVisualParent.DO); } return(fo.DO); }
// 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); } }
// Token: 0x06000693 RID: 1683 RVA: 0x00014CD4 File Offset: 0x00012ED4 internal FrameworkObject InstantiateUnoptimizedTree() { if (!this._sealed) { throw new InvalidOperationException(SR.Get("FrameworkElementFactoryMustBeSealed")); } FrameworkObject result = new FrameworkObject(this.CreateDependencyObject()); result.BeginInit(); ProvideValueServiceProvider provideValueServiceProvider = null; FrameworkTemplate.SetTemplateParentValues(this.Name, result.DO, this._frameworkTemplate, ref provideValueServiceProvider); FrameworkElementFactory frameworkElementFactory = this._firstChild; IAddChild addChild = null; if (frameworkElementFactory != null) { addChild = (result.DO as IAddChild); if (addChild == null) { throw new InvalidOperationException(SR.Get("TypeMustImplementIAddChild", new object[] { result.DO.GetType().Name })); } } while (frameworkElementFactory != null) { if (frameworkElementFactory._text != null) { addChild.AddText(frameworkElementFactory._text); } else { FrameworkObject childFrameworkObject = frameworkElementFactory.InstantiateUnoptimizedTree(); this.AddNodeToParent(result.DO, childFrameworkObject); } frameworkElementFactory = frameworkElementFactory._nextSibling; } result.EndInit(); return(result); }
// Token: 0x06000C1F RID: 3103 RVA: 0x0002D454 File Offset: 0x0002B654 object INameScope.FindName(string name) { if (this._templatedParent != null) { FrameworkObject frameworkObject = new FrameworkObject(this._templatedParent); if (frameworkObject.IsFE) { return(StyleHelper.FindNameInTemplateContent(frameworkObject.FE, name, frameworkObject.FE.TemplateInternal)); } return(null); } else { if (this._nameMap == null || name == null || name == string.Empty) { return(null); } return(this._nameMap[name]); } }
/// <summary> /// Evaluate the HasLoadedChangeHandler flag on the given node by /// querying its children, and styles, and templates. /// </summary> /// <param name="fo"> /// Node /// </param> private static bool AreThereLoadedChangeHandlersInSubtree(ref FrameworkObject fo) { // HasHandler flag can be evaluated only for a FE/FCE. if (!fo.IsValid) { return(false); } if (fo.ThisHasLoadedChangeEventHandler) { return(true); } if (fo.IsFE) { // Check if any of your visual children have the flag set Visual v = (Visual)fo.FE; int count = VisualTreeHelper.GetChildrenCount(v); for (int i = 0; i < count; i++) { FrameworkElement child = VisualTreeHelper.GetChild(v, i) as FrameworkElement; if (child != null && child.SubtreeHasLoadedChangeHandler) { return(true); } } } // Check if any of your logical children have the flag set foreach (object o in LogicalTreeHelper.GetChildren(fo.DO)) { DependencyObject child = o as DependencyObject; if (null != child && SubtreeHasLoadedChangeHandlerHelper(child)) { return(true); } } return(false); }
/// <summary>Indicates whether a specified element belongs to an instance of a template that defines a value for the specified property that may change at runtime based on changes elsewhere. </summary> /// <param name="elementInTemplate">An element that belongs to a template instance. </param> /// <param name="dependencyProperty">A dependency property. </param> /// <returns> /// <see langword="true" /> if <paramref name="elementInTemplate" /> belongs to an instance of a template that defines a value for the specified property that may change at runtime based on changes elsewhere; otherwise, <see langword="false" />. </returns> // Token: 0x060003BA RID: 954 RVA: 0x0000A9B8 File Offset: 0x00008BB8 public static bool IsTemplatedValueDynamic(DependencyObject elementInTemplate, DependencyProperty dependencyProperty) { if (elementInTemplate == null) { throw new ArgumentNullException("elementInTemplate"); } if (dependencyProperty == null) { throw new ArgumentNullException("dependencyProperty"); } FrameworkObject frameworkObject = new FrameworkObject(elementInTemplate); DependencyObject templatedParent = frameworkObject.TemplatedParent; if (templatedParent == null) { throw new ArgumentException(SR.Get("ElementMustBelongToTemplate"), "elementInTemplate"); } int templateChildIndex = frameworkObject.TemplateChildIndex; return(StyleHelper.IsValueDynamic(templatedParent, templateChildIndex, dependencyProperty)); }
// Token: 0x0600030C RID: 780 RVA: 0x00008740 File Offset: 0x00006940 private static void BroadcastEvent(DependencyObject root, RoutedEvent routedEvent) { List <DependencyObject> list = new List <DependencyObject>(); DescendentsWalker <BroadcastEventHelper.BroadcastEventData> descendentsWalker = new DescendentsWalker <BroadcastEventHelper.BroadcastEventData>(TreeWalkPriority.VisualTree, BroadcastEventHelper.BroadcastDelegate, new BroadcastEventHelper.BroadcastEventData(root, routedEvent, list)); descendentsWalker.StartWalk(root); for (int i = 0; i < list.Count; i++) { DependencyObject dependencyObject = list[i]; RoutedEventArgs args = new RoutedEventArgs(routedEvent, dependencyObject); FrameworkObject frameworkObject = new FrameworkObject(dependencyObject, true); if (routedEvent == FrameworkElement.LoadedEvent) { frameworkObject.OnLoaded(args); } else { frameworkObject.OnUnloaded(args); } } }
// protected internal void AddLogicalChild(object child) { if (child != null) { // It is invalid to modify the children collection that we // might be iterating during a property invalidation tree walk. if (IsLogicalChildrenIterationInProgress) { throw new InvalidOperationException(SR.Get(SRID.CannotModifyLogicalChildrenDuringTreeWalk)); } // Now that the child is going to be added, the FE/FCE construction is considered finished, // so we do not expect a change of InheritanceBehavior property, // so we can pick up properties from styles and resources. TryFireInitialized(); bool exceptionThrown = true; try { HasLogicalChildren = true; // Child is present; reparent him to this element FrameworkObject fo = new FrameworkObject(child as DependencyObject); fo.ChangeLogicalParent(this); exceptionThrown = false; } finally { if (exceptionThrown) { // // Consider doing this... //RemoveLogicalChild(child); } } } }
// Token: 0x06007608 RID: 30216 RVA: 0x0021A9AC File Offset: 0x00218BAC private DependencyObject FindAncestorOfType(Type type, int level, DependencyObject d, bool isTracing) { if (type == null) { if (TraceData.IsEnabled) { TraceData.Trace(TraceEventType.Error, TraceData.RefAncestorTypeNotSpecified); } return(null); } if (level < 1) { if (TraceData.IsEnabled) { TraceData.Trace(TraceEventType.Error, TraceData.RefAncestorLevelInvalid); } return(null); } FrameworkObject frameworkObject = new FrameworkObject(d); frameworkObject.Reset(frameworkObject.GetPreferVisualParent(true).DO); while (frameworkObject.DO != null) { if (isTracing) { TraceData.Trace(TraceEventType.Warning, TraceData.AncestorLookup(new object[] { type.Name, TraceData.Identify(frameworkObject.DO) })); } if (type.IsInstanceOfType(frameworkObject.DO) && --level <= 0) { break; } frameworkObject.Reset(frameworkObject.PreferVisualParent.DO); } return(frameworkObject.DO); }
/// <summary> /// This method is invoked when the Content property changes. /// </summary> /// <param name="oldContent">The old value of the Content property.</param> /// <param name="newContent">The new value of the Content property.</param> protected virtual void OnContentChanged(object oldContent, object newContent) { // Remove the old content child RemoveLogicalChild(oldContent); // if Content should not be treated as a logical child, there's // nothing to do if (ContentIsNotLogical) { return; } DependencyObject d = newContent as DependencyObject; if (d != null) { DependencyObject logicalParent = LogicalTreeHelper.GetParent(d); if (logicalParent != null) { if (TemplatedParent != null && FrameworkObject.IsEffectiveAncestor(logicalParent, this)) { // In the case that this ContentControl belongs in a parent template // and represents the content of a parent, we do not wish to change // the logical ancestry of the content. return; } else { // If the new content was previously hooked up to the logical // tree then we sever it from the old parent. LogicalTreeHelper.RemoveLogicalChild(logicalParent, newContent); } } } // Add the new content child AddLogicalChild(newContent); }
private static CommandBinding SetCommandBinding([CanBeNull] DependencyObject obj, [CanBeNull] ICommand command) { while (obj != null && !(obj is Window || obj is UserControl || GetCommandScope(obj))) { var temp = new FrameworkObject(obj, false); obj = temp.Parent ?? temp.VisualParent; } if (obj == null || command == null) return null; CommandBindingCollection commandBindings = ((UIElement) obj).CommandBindings; CommandBinding binding = commandBindings.OfType<CommandBinding>().FirstOrDefault(cb => cb.Command == command); if (binding != null) return null; binding = new CommandBinding(command); commandBindings.Add(binding); return binding; }
private static void ImportPropertyChanged([NotNull] DependencyObject d, DependencyPropertyChangedEventArgs e) { if (DesignerProperties.GetIsInDesignMode(d)) return; try { IEnumerable<IViewAggregatorAdapter> adapters = Container.ResolveAll<IViewAggregatorAdapter>(null); IViewAggregatorAdapter adapter = adapters.FirstOrDefault(a => a.CanAdapt(d)); if (adapter == null) { var obj = new FrameworkObject(d); IEnumerable<object> views = Container.ResolveAll((Type) e.NewValue, null); obj.DataContext = views.FirstOrDefault(); return; } lock (adapter) { adapter.Adapt(d); IEnumerable<object> views = Container.ResolveAll((Type) e.NewValue, null); adapter.AddViews(views); adapter.Release(); } } catch (Exception ex) { if (ExceptionPolicy.HandleException(ex, CommonWpfConstans.CommonExceptionPolicy)) throw; } }
internal static object FindDataContext([CanBeNull] DependencyObject obj) { if (obj == null) return null; object result = new FrameworkObject(obj, false).DataContext ?? obj.GetValue(DataContextProperty); return result; }
private static ObjectReference FindObjectRecusiv([CanBeNull] DependencyObject element) { ObjectReference objRef; do { objRef = FindObject(element); if (objRef != null) break; var temp = new FrameworkObject(element, false); element = temp.Parent ?? temp.VisualParent; } while (element != null); return objRef; }
/// <summary> /// Initializes a new instance of the <see cref="RequestingElement" /> class. /// Initialisiert eine neue Instanz der <see cref="RequestingElement" /> Klasse. /// </summary> /// <param name="obj"> /// The obj. /// </param> /// <param name="pipline"> /// The pipline. /// </param> public RequestingElement([CanBeNull] DependencyObject obj, [NotNull] IPipeLine pipline) { _depObj = new FrameworkObject(obj); _pipline = pipline; _depObj.LoadedEvent += LoadedEventHandler; }