示例#1
0
        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);
        }
示例#2
0
        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));
        }
示例#3
0
        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);
            }
        }
示例#4
0
        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);
        }
示例#5
0
        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);
            }
        }
示例#6
0
        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);
            }
        }
示例#7
0
        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);
        }