示例#1
0
        public static void DeleteStateGroup(SceneNode ownerNode, VisualStateGroupSceneNode nodeToRemove)
        {
            IList <VisualStateGroupSceneNode> stateGroups = VisualStateManagerSceneNode.GetStateGroups(ownerNode);

            stateGroups.Remove(nodeToRemove);
            if (stateGroups.Count != 0)
            {
                return;
            }
            ownerNode.ClearLocalValue(VisualStateManagerSceneNode.VisualStateGroupsProperty);
        }
示例#2
0
        public static void AddDefaultStates(SceneNode ownerNode, SceneNode rootNode, ITypeId controlTypeId)
        {
            IType           controlType    = ownerNode.ProjectContext.ResolveType(controlTypeId);
            IProjectContext projectContext = ownerNode.ProjectContext;

            if (projectContext != null && projectContext.IsCapabilitySet(PlatformCapability.VsmInToolkit) && (projectContext.IsCapabilitySet(PlatformCapability.SupportsVisualStateManager) && projectContext.PlatformMetadata.IsNullType((ITypeId)projectContext.ResolveType(ProjectNeutralTypes.VisualStateManager))))
            {
                IAssembly usingAssemblyName = ((PlatformTypes)projectContext.Platform.Metadata).GetPlatformAssemblyUsingAssemblyName(controlType.RuntimeAssembly);
                if (usingAssemblyName == null || !AssemblyHelper.IsPlatformAssembly(usingAssemblyName))
                {
                    ToolkitProjectContext toolkitProjectContext = new ToolkitProjectContext(projectContext);
                    if (ProjectAttributeHelper.GetDefaultStateRecords(controlType, (ITypeResolver)toolkitProjectContext).Count > 0)
                    {
                        ToolkitHelper.AddToolkitReferenceIfNeeded((ITypeResolver)projectContext, ownerNode.DesignerContext.ViewUpdateManager);
                    }
                }
            }
            foreach (DefaultStateRecord defaultStateRecord in ProjectAttributeHelper.GetDefaultStateRecords(controlType, (ITypeResolver)ownerNode.ProjectContext.GetService(typeof(ProjectContext))))
            {
                IList <VisualStateGroupSceneNode> stateGroups          = VisualStateManagerSceneNode.GetStateGroups(ownerNode);
                VisualStateGroupSceneNode         stateGroupSceneNode1 = (VisualStateGroupSceneNode)null;
                foreach (VisualStateGroupSceneNode stateGroupSceneNode2 in (IEnumerable <VisualStateGroupSceneNode>)stateGroups)
                {
                    if (stateGroupSceneNode2.Name == defaultStateRecord.GroupName)
                    {
                        stateGroupSceneNode1 = stateGroupSceneNode2;
                    }
                }
                if (stateGroupSceneNode1 == null)
                {
                    VisualStateManagerSceneNode.EnsureNameAvailable(rootNode, defaultStateRecord.GroupName);
                    stateGroupSceneNode1 = VisualStateManagerSceneNode.AddStateGroup(ownerNode, rootNode, defaultStateRecord.GroupName);
                    stateGroupSceneNode1.ShouldSerialize = false;
                }
                VisualStateSceneNode visualStateSceneNode1 = (VisualStateSceneNode)null;
                if (stateGroupSceneNode1 != null)
                {
                    foreach (VisualStateSceneNode visualStateSceneNode2 in (IEnumerable <VisualStateSceneNode>)stateGroupSceneNode1.States)
                    {
                        if (visualStateSceneNode2.Name == defaultStateRecord.StateName)
                        {
                            visualStateSceneNode1 = visualStateSceneNode2;
                        }
                    }
                    if (visualStateSceneNode1 == null)
                    {
                        VisualStateManagerSceneNode.EnsureNameAvailable(rootNode, defaultStateRecord.StateName);
                        stateGroupSceneNode1.AddState(rootNode, defaultStateRecord.StateName);
                    }
                }
            }
        }
        public void UpdateAutoTransitions()
        {
            VisualStateGroupSceneNode stateGroup = this.StateGroup;

            if (stateGroup == null || !stateGroup.IsSketchFlowAnimation)
            {
                return;
            }
            foreach (VisualStateTransitionSceneNode transitionSceneNode in (IEnumerable <VisualStateTransitionSceneNode>)stateGroup.Transitions)
            {
                if (transitionSceneNode.ToStateName != null && transitionSceneNode.ToStateName == this.Name)
                {
                    transitionSceneNode.UpdateAutoTransitionsForState(this);
                }
            }
        }
        public void UpdateTransitionsForStateValueChange(TimelineSceneNode.PropertyNodePair targetElementAndProperty, object newValue)
        {
            VisualStateGroupSceneNode stateGroup = this.StateGroup;

            if (stateGroup != null)
            {
                foreach (VisualStateTransitionSceneNode transitionSceneNode in (IEnumerable <VisualStateTransitionSceneNode>)stateGroup.Transitions)
                {
                    if (transitionSceneNode.ToStateName == this.Name)
                    {
                        transitionSceneNode.UpdateToValuesForStateValueChange(targetElementAndProperty, newValue);
                    }
                }
            }
            this.UpdateAutoTransitions();
        }
示例#5
0
        public static VisualStateGroupSceneNode AddStateGroup(SceneNode ownerNode, SceneNode rootNode, string groupName)
        {
            ProjectContext projectContext = (ProjectContext)ownerNode.ProjectContext.GetService(typeof(ProjectContext));

            ToolkitHelper.AddToolkitReferenceIfNeeded((ITypeResolver)projectContext, ownerNode.DesignerContext.ViewUpdateManager);
            IType type = projectContext.ResolveType(ProjectNeutralTypes.VisualStateGroup);

            if (type == null || projectContext.PlatformMetadata.IsNullType((ITypeId)type))
            {
                return((VisualStateGroupSceneNode)null);
            }
            VisualStateGroupSceneNode stateGroupSceneNode = VisualStateGroupSceneNode.Factory.Instantiate(ownerNode.ViewModel);

            VisualStateManagerSceneNode.GetStateGroups(ownerNode).Add(stateGroupSceneNode);
            string validElementId = new SceneNodeIDHelper(ownerNode.ViewModel, rootNode).GetValidElementID((SceneNode)stateGroupSceneNode, groupName);

            stateGroupSceneNode.Name = validElementId;
            return(stateGroupSceneNode);
        }
        protected override void OnChildRemoving(SceneNode child)
        {
            base.OnChildRemoving(child);
            TimelineSceneNode timeline = child as TimelineSceneNode;

            if (this.ViewModel.AnimationProxyManager != null && AnimationProxyManager.IsAnimationProxy(timeline))
            {
                this.ViewModel.AnimationProxyManager.UpdateOnDeletion(child as KeyFrameAnimationSceneNode);
            }
            VisualStateSceneNode controllingState = this.ControllingState;

            if (controllingState == null)
            {
                return;
            }
            TimelineSceneNode.PropertyNodePair propertyNodePair = timeline != null ? timeline.TargetElementAndProperty : new TimelineSceneNode.PropertyNodePair((SceneNode)null, (PropertyReference)null);
            VisualStateGroupSceneNode          stateGroup       = controllingState.StateGroup;

            if (propertyNodePair.SceneNode == null || propertyNodePair.PropertyReference == null || (!timeline.ShouldSerialize || stateGroup == null))
            {
                return;
            }
            List <KeyValuePair <VisualStateSceneNode, bool> > list = new List <KeyValuePair <VisualStateSceneNode, bool> >(stateGroup.States.Count);

            list.Add(new KeyValuePair <VisualStateSceneNode, bool>(controllingState, true));
            foreach (VisualStateTransitionSceneNode transitionSceneNode in (IEnumerable <VisualStateTransitionSceneNode>)stateGroup.Transitions)
            {
                if (transitionSceneNode.Storyboard != null && (!string.IsNullOrEmpty(transitionSceneNode.FromStateName) || !string.IsNullOrEmpty(transitionSceneNode.ToStateName)))
                {
                    VisualStateSceneNode fromState = transitionSceneNode.FromState;
                    VisualStateSceneNode toState   = transitionSceneNode.ToState;
                    if (fromState == controllingState || toState == controllingState)
                    {
                        TimelineSceneNode timelineSceneNode = (TimelineSceneNode)transitionSceneNode.Storyboard.GetAnimation(propertyNodePair.SceneNode, propertyNodePair.PropertyReference);
                        if (timelineSceneNode != null)
                        {
                            VisualStateSceneNode key = fromState == controllingState ? toState : fromState;
                            bool?nullable            = new bool?();
                            if (key == null)
                            {
                                nullable = new bool?(false);
                            }
                            if (!nullable.HasValue)
                            {
                                foreach (KeyValuePair <VisualStateSceneNode, bool> keyValuePair in list)
                                {
                                    if (keyValuePair.Key == key)
                                    {
                                        nullable = new bool?(keyValuePair.Value);
                                    }
                                }
                            }
                            if (!nullable.HasValue)
                            {
                                nullable = new bool?(key.Storyboard != null && key.Storyboard.GetAnimation(propertyNodePair.SceneNode, propertyNodePair.PropertyReference) != null);
                                list.Add(new KeyValuePair <VisualStateSceneNode, bool>(key, nullable.Value));
                            }
                            if (!nullable.Value)
                            {
                                transitionSceneNode.Storyboard.Children.Remove(timelineSceneNode);
                            }
                        }
                    }
                }
            }
        }