public void Apply(FrameworkElement target, BaseValueSource valueSource) { INameScope nameScope = valueSource == BaseValueSource.Local ? NameScope.GetContainingNameScope(target) : NameScope.GetTemplateNameScope(target); object layerOwner = valueSource == BaseValueSource.Local ? null : target.TemplatedParent; Begin(target, nameScope, layerOwner); }
public void ContainingNameScopeTest() { FrameworkElement logicalParent = new FrameworkElement(); FrameworkElement visualParent = new FrameworkElement(); FrameworkElement child = new FrameworkElement(); NameScope logicalNameScope = new NameScope(); NameScope.SetNameScope(logicalParent, logicalNameScope); NameScope visualNameScope = new NameScope(); NameScope.SetNameScope(visualParent, visualNameScope); Freezable value = new Freezable(); Freezable subValue = new Freezable(); // visual / context tree: logicalParent -> visualParent -> child -> value -> subValue logicalParent.AddVisualChild(visualParent); visualParent.AddVisualChild(child); child.SetValue(ValueProperty, value); value.SetValue(ValueProperty, subValue); // logical tree: logicalParent -> child logicalParent.AddLogicalChild(child); Assert.AreEqual(logicalNameScope, NameScope.GetContainingNameScope(subValue)); }
public override void Apply(FrameworkElement target, BaseValueSource valueSource) { BeginStoryboard beginStoryboard = GetBeginStoryboard(target); if (beginStoryboard != null) { INameScope nameScope = valueSource == BaseValueSource.Local ? NameScope.GetContainingNameScope(target) : NameScope.GetTemplateNameScope(target); object layerOwner = valueSource == BaseValueSource.Local ? null : target.TemplatedParent; beginStoryboard.Remove(target, nameScope, layerOwner); } }
private static object GetRelativeSource(DependencyObject target, RelativeSource relativeSource, string elementName) { if (!elementName.IsNullOrEmpty()) { INameScope nameScope = NameScope.GetContainingNameScope(target); return(nameScope != null?nameScope.FindName(elementName) : null); } if (relativeSource == null || relativeSource.Mode == RelativeSourceMode.Self) { return(target); } if (relativeSource.Mode == RelativeSourceMode.TemplatedParent) { return(target is FrameworkElement ? ((FrameworkElement)target).TemplatedParent : null); } if (relativeSource.Mode == RelativeSourceMode.FindAncestor) { if (!(target is Visual)) { return(null); } Visual visual = (target as Visual).VisualParent; int level = relativeSource.AncestorLevel - 1; while (visual != null && (level > 0 || relativeSource.AncestorType != null && !relativeSource.AncestorType.IsInstanceOfType(visual))) { if (relativeSource.AncestorType == null || relativeSource.AncestorType.IsInstanceOfType(visual)) { level--; } visual = visual.VisualParent; } return(visual); } throw new Granular.Exception("RelativeSourceMode \"{0}\" is unexpected", relativeSource.Mode); }
public void Begin(FrameworkElement containingObject, INameScope nameScope = null, HandoffBehavior handoffBehavior = HandoffBehavior.SnapshotAndReplace, object layerOwner = null) { Stop(containingObject); TimelineClock clock = CreateClock(); clock.Begin(((IAnimatable)containingObject).RootClock); clocks[containingObject] = clock; ListDictionary <TargetKey, AnimationTimelineClock> targets = GetAnimationClocksTargets(clock, containingObject, nameScope ?? NameScope.GetContainingNameScope(containingObject)); foreach (TargetKey target in targets.GetKeys()) { target.Target.ApplyAnimationClocks(target.TargetProperty, targets.GetValues(target), handoffBehavior, layerOwner); } }
public void Remove(FrameworkElement containingObject, INameScope nameScope = null, object layerOwner = null) { Stop(containingObject); TimelineClock clock; if (clocks.TryGetValue(containingObject, out clock)) { ListDictionary <TargetKey, AnimationTimelineClock> targets = GetAnimationClocksTargets(clock, containingObject, nameScope ?? NameScope.GetContainingNameScope(containingObject)); foreach (TargetKey target in targets.GetKeys()) { target.Target.RemoveAnimationClocks(target.TargetProperty, targets.GetValues(target), layerOwner); } clocks.Remove(containingObject); } }
protected BeginStoryboard GetBeginStoryboard(FrameworkElement target) { INameScope nameScope = NameScope.GetContainingNameScope(target); return(nameScope != null?nameScope.FindName(BeginStoryboardName) as BeginStoryboard : null); }
private static object GetScopeElement(DependencyObject target, string elementName) { INameScope nameScope = NameScope.GetContainingNameScope(target); return(nameScope != null?nameScope.FindName(elementName) : ObservableValue.UnsetValue); }