コード例 #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
ファイル: Storyboard.cs プロジェクト: portalninja/Granular
        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
ファイル: Storyboard.cs プロジェクト: portalninja/Granular
        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);
        }
コード例 #8
0
        private static object GetScopeElement(DependencyObject target, string elementName)
        {
            INameScope nameScope = NameScope.GetContainingNameScope(target);

            return(nameScope != null?nameScope.FindName(elementName) : ObservableValue.UnsetValue);
        }