Пример #1
0
        public static void MoveStates(SceneElement source, SceneElement target)
        {
            if (source == null || target == null || source.ProjectContext.PlatformMetadata.IsNullType((ITypeId)source.ProjectContext.ResolveType(ProjectNeutralTypes.VisualStateManager)))
            {
                return;
            }
            IList <VisualStateGroupSceneNode> stateGroups = VisualStateManagerSceneNode.GetStateGroups((SceneNode)target);

            stateGroups.Clear();
            ISceneNodeCollection <SceneNode> collectionForProperty = source.GetCollectionForProperty(VisualStateManagerSceneNode.VisualStateGroupsProperty);
            List <VisualStateGroupSceneNode> list = new List <VisualStateGroupSceneNode>();

            foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)collectionForProperty)
            {
                if (sceneNode is VisualStateGroupSceneNode)
                {
                    list.Add((VisualStateGroupSceneNode)VisualStateGroupSceneNode.Factory.Instantiate(target.ViewModel, sceneNode.DocumentNode.Clone(target.DocumentContext)));
                }
            }
            collectionForProperty.Clear();
            foreach (VisualStateGroupSceneNode stateGroupSceneNode in list)
            {
                stateGroups.Add(stateGroupSceneNode);
            }
        }
Пример #2
0
        public static bool GetHasExtendedVisualStateManager(SceneNode ownerNode)
        {
            VisualStateManagerSceneNode visualStateManager = VisualStateManagerSceneNode.GetCustomVisualStateManager(ownerNode);

            if (visualStateManager != null)
            {
                return(ProjectNeutralTypes.ExtendedVisualStateManager.IsAssignableFrom((ITypeId)visualStateManager.Type));
            }
            return(false);
        }
Пример #3
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);
        }
Пример #4
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);
                    }
                }
            }
        }
Пример #5
0
        public static void UpdateHasExtendedVisualStateManager(SceneNode editingContainer)
        {
            SceneNode hostNode = VisualStateManagerSceneNode.GetHostNode(editingContainer);

            if (hostNode == null)
            {
                return;
            }
            IList <VisualStateGroupSceneNode> stateGroups = VisualStateManagerSceneNode.GetStateGroups(hostNode);
            bool flag1 = stateGroups.Count > 0;
            bool flag2 = false;

            if (flag1)
            {
                IProperty property1 = editingContainer.ProjectContext.ResolveProperty(VisualStateManagerSceneNode.UseFluidLayoutProperty);
                IProperty property2 = editingContainer.ProjectContext.ResolveProperty(VisualStateManagerSceneNode.TransitionEffectProperty);
                if (property1 != null)
                {
                    foreach (VisualStateGroupSceneNode stateGroupSceneNode in (IEnumerable <VisualStateGroupSceneNode>)stateGroups)
                    {
                        if ((bool)stateGroupSceneNode.GetLocalOrDefaultValue((IPropertyId)property1))
                        {
                            flag2 = true;
                            break;
                        }
                        if (property2 != null)
                        {
                            foreach (SceneNode sceneNode in (IEnumerable <VisualStateTransitionSceneNode>)stateGroupSceneNode.Transitions)
                            {
                                if (sceneNode.GetLocalOrDefaultValue((IPropertyId)property2) != null)
                                {
                                    flag2 = true;
                                    break;
                                }
                            }
                            if (flag2)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            bool set = flag2 || flag1 && VisualStateManagerSceneNode.CanOnlySupportExtendedVisualStateManager(editingContainer);

            if (VisualStateManagerSceneNode.GetHasExtendedVisualStateManager(hostNode) == set)
            {
                return;
            }
            VisualStateManagerSceneNode.SetHasExtendedVisualStateManager(hostNode, set);
        }
Пример #6
0
        public static void SetHasExtendedVisualStateManager(SceneNode ownerNode, bool set)
        {
            ProjectContext   projectContext  = ownerNode.ProjectContext as ProjectContext;
            IAssemblyService assemblyService = ownerNode.DesignerContext.AssemblyService;

            if (set)
            {
                if (!VisualStateManagerSceneNode.EnsureExtendedAssemblyReferences((ITypeResolver)projectContext, assemblyService, ownerNode.DesignerContext.ViewUpdateManager))
                {
                    return;
                }
                ownerNode.SetValueAsSceneNode(VisualStateManagerSceneNode.CustomVisualStateManagerProperty, ownerNode.ViewModel.CreateSceneNode(ProjectNeutralTypes.ExtendedVisualStateManager));
            }
            else
            {
                ownerNode.ClearValue(VisualStateManagerSceneNode.CustomVisualStateManagerProperty);
            }
        }
Пример #7
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);
        }
        public void Insert(SceneNode nodeToInsert)
        {
            ISceneNodeCollection <SceneNode> collectionForProperty = this.SceneNode.GetCollectionForProperty((IPropertyId)this.Property);

            if (collectionForProperty.FixedCapacity.HasValue && collectionForProperty.Count >= collectionForProperty.FixedCapacity.Value)
            {
                PropertySceneInsertionPoint.Cleanup(collectionForProperty[collectionForProperty.Count - 1]);
            }
            collectionForProperty.Add(nodeToInsert);
            ControlTemplateElement controlTemplateElement = this.SceneNode as ControlTemplateElement;

            if (controlTemplateElement == null)
            {
                return;
            }
            ITypeId templateTargetTypeId = controlTemplateElement.ControlTemplateTargetTypeId;

            VisualStateManagerSceneNode.AddDefaultStates(nodeToInsert, (SceneNode)controlTemplateElement, templateTargetTypeId);
        }
Пример #9
0
 public static VisualStateGroupSceneNode FindGroupByName(SceneNode ownerNode, string name)
 {
     foreach (VisualStateGroupSceneNode stateGroupSceneNode in (IEnumerable <VisualStateGroupSceneNode>)VisualStateManagerSceneNode.GetStateGroups(ownerNode))
     {
         if (stateGroupSceneNode.Name == name)
         {
             return(stateGroupSceneNode);
         }
     }
     return((VisualStateGroupSceneNode)null);
 }
Пример #10
0
 public static bool CanSupportVisualStateManager(SceneNode editingContainer)
 {
     return(editingContainer != null && (PlatformTypes.UserControl.IsAssignableFrom((ITypeId)editingContainer.Type) || PlatformTypes.ControlTemplate.IsAssignableFrom((ITypeId)editingContainer.Type) || !PlatformTypes.Style.IsAssignableFrom((ITypeId)editingContainer.Type) && (editingContainer.ProjectContext.IsCapabilitySet(PlatformCapability.VsmEverywhereByDefault) || VisualStateManagerSceneNode.CanSupportExtendedVisualStateManager(editingContainer))));
 }
Пример #11
0
        private bool UpdateTransitionTimelineForState(VisualStateSceneNode state, bool stateIsFromState, bool updateDocument, Dictionary <TimelineSceneNode.PropertyNodePair, TransitionAnimationData> animations, StoryboardTimelineSceneNode transitionStoryboard)
        {
            bool      flag1    = false;
            bool      flag2    = false;
            IProperty property = this.ProjectContext.ResolveProperty(VisualStateManagerSceneNode.TransitionEffectProperty);

            if (property != null && this.GetLocalValueAsDocumentNode((IPropertyId)property) != null)
            {
                flag2 = true;
            }
            if (state != null && state.Storyboard != null)
            {
                foreach (TimelineSceneNode timelineSceneNode in (IEnumerable <TimelineSceneNode>)state.Storyboard.Children)
                {
                    TransitionAnimationData transitionAnimationData = (TransitionAnimationData)null;
                    AnimationSceneNode      stateAnimation          = timelineSceneNode as AnimationSceneNode;
                    if (stateAnimation != null && stateAnimation.ShouldSerialize)
                    {
                        if (!animations.TryGetValue(stateAnimation.TargetElementAndProperty, out transitionAnimationData))
                        {
                            ITypeId animatedType = stateAnimation.AnimatedType;
                            bool    isConforming = VisualStateManagerSceneNode.IsSupportedTransitionAnimationType(animatedType);
                            if (updateDocument)
                            {
                                TimelineSceneNode.PropertyNodePair elementAndProperty = stateAnimation.TargetElementAndProperty;
                                if (isConforming && !flag2 && (elementAndProperty.SceneNode != null && elementAndProperty.PropertyReference != null))
                                {
                                    FromToAnimationSceneNode animationSceneNode1 = FromToAnimationSceneNode.Factory.InstantiateWithTarget(stateAnimation.ViewModel, elementAndProperty.SceneNode, elementAndProperty.PropertyReference, stateAnimation.StoryboardContainer, FromToAnimationSceneNode.GetFromToAnimationForType(animatedType, stateAnimation.ProjectContext));
                                    animationSceneNode1.EasingFunction = this.GeneratedEasingFunction;
                                    AnimationSceneNode animationSceneNode2 = (AnimationSceneNode)animationSceneNode1;
                                    transitionStoryboard.Children.Add((TimelineSceneNode)animationSceneNode2);
                                    animationSceneNode1.ShouldSerialize = false;
                                    transitionAnimationData             = new TransitionAnimationData((AnimationSceneNode)animationSceneNode1, true);
                                    animations[stateAnimation.TargetElementAndProperty] = transitionAnimationData;
                                }
                                else
                                {
                                    transitionAnimationData = new TransitionAnimationData((AnimationSceneNode)null, false);
                                    animations[stateAnimation.TargetElementAndProperty] = transitionAnimationData;
                                }
                            }
                            else
                            {
                                transitionAnimationData = new TransitionAnimationData((AnimationSceneNode)null, isConforming);
                                animations[stateAnimation.TargetElementAndProperty] = transitionAnimationData;
                            }
                        }
                        else if (flag2 && transitionAnimationData.TransitionAnimation != null && !transitionAnimationData.TransitionAnimation.ShouldSerialize)
                        {
                            if (updateDocument)
                            {
                                transitionStoryboard.Children.Remove((TimelineSceneNode)transitionAnimationData.TransitionAnimation);
                            }
                            transitionAnimationData.TransitionAnimation = (AnimationSceneNode)null;
                        }
                        AnimationSceneNode transitionAnimation = transitionAnimationData.TransitionAnimation;
                        if (transitionAnimation != null)
                        {
                            FromToAnimationSceneNode animationSceneNode = transitionAnimation as FromToAnimationSceneNode;
                            if (animationSceneNode != null)
                            {
                                object objB = !stateIsFromState?VisualStateTransitionSceneNode.GetTransitionValue(stateAnimation, stateIsFromState) : (object)null;

                                if (!transitionAnimation.ShouldSerialize)
                                {
                                    if (updateDocument)
                                    {
                                        if (!stateIsFromState)
                                        {
                                            animationSceneNode.To = objB;
                                        }
                                        Duration generatedDuration = this.GeneratedDuration;
                                        if (generatedDuration.HasTimeSpan)
                                        {
                                            animationSceneNode.Duration = generatedDuration.TimeSpan.TotalSeconds;
                                        }
                                        else
                                        {
                                            animationSceneNode.Duration = 0.0;
                                        }
                                        animationSceneNode.EasingFunction  = this.GeneratedEasingFunction;
                                        animationSceneNode.ShouldSerialize = false;
                                    }
                                }
                                else
                                {
                                    transitionAnimationData.IsConforming = !stateIsFromState ? animationSceneNode.From == null && object.Equals(animationSceneNode.To, objB) : animationSceneNode.To == null;
                                    flag1 = true;
                                }
                            }
                            else
                            {
                                flag1 = true;
                            }
                        }
                    }
                }
            }
            return(flag1);
        }