Ejemplo n.º 1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            PropertyReferencePropertyValue referencePropertyValue = value as PropertyReferencePropertyValue;

            if (referencePropertyValue != null)
            {
                SceneNodeProperty sceneNodeProperty = referencePropertyValue.OwnerProperty as SceneNodeProperty;
                if (sceneNodeProperty != null)
                {
                    IProjectContext projectContext = sceneNodeProperty.SceneNodeObjectSet.ProjectContext;
                    if (projectContext == null)
                    {
                        return(null);
                    }
                    Type runtimeType1 = projectContext.ResolveType(ProjectNeutralTypes.BehaviorEventTriggerBase).RuntimeType;
                    Type runtimeType2 = projectContext.ResolveType(ProjectNeutralTypes.BehaviorTargetedTriggerAction).RuntimeType;
                    Type type         = sceneNodeProperty.ObjectSet.ObjectType;
                    while (type != (Type)null && type.BaseType != (Type)null && (!type.BaseType.Equals(runtimeType1) && !type.BaseType.Equals(runtimeType2)))
                    {
                        type = type.BaseType;
                    }
                    Type[] genericArguments = type.GetGenericArguments();
                    if (genericArguments.Length > 0)
                    {
                        return((object)projectContext.GetType(genericArguments[0]));
                    }
                    return((object)type);
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        private static void TransferPathFigureAnimations(PathElement oldElement, PathElement newElement, PropertyReference pathProperty, int oldFigureIndex, int newFigureIndex, Transform transform, PathAnimationMovePackage animationMove)
        {
            IProjectContext   projectContext             = newElement.ProjectContext;
            IType             type                       = projectContext.ResolveType(PlatformTypes.PathFigureCollection);
            PropertyReference propertyReference          = pathProperty.Append(PathElement.FiguresProperty);
            ReferenceStep     step1                      = (ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep((ITypeResolver)projectContext, type.RuntimeType, oldFigureIndex);
            PropertyReference sourceReferencePrefix      = propertyReference.Append(step1);
            ReferenceStep     step2                      = (ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep((ITypeResolver)projectContext, type.RuntimeType, newFigureIndex);
            PropertyReference destinationReferencePrefix = propertyReference.Append(step2);

            PathCommandHelper.MoveVertexAnimations((SceneElement)oldElement, sourceReferencePrefix, (SceneElement)newElement, destinationReferencePrefix, transform, animationMove);
        }
Ejemplo n.º 3
0
        public static bool DoesStyleTargetControl(IProjectContext projectContext, IType elementType, IPropertyId styleProperty)
        {
            IProperty property           = projectContext.ResolveProperty(styleProperty);
            Type      propertyTargetType = elementType.Metadata.GetStylePropertyTargetType((IPropertyId)property);
            Type      runtimeType        = projectContext.ResolveType(PlatformTypes.Control).RuntimeType;

            if (propertyTargetType != (Type)null)
            {
                return(runtimeType.IsAssignableFrom(propertyTargetType));
            }
            return(false);
        }
Ejemplo n.º 4
0
        public override SceneNode CreatePrototypeInstance(ISceneInsertionPoint insertionPoint)
        {
            IProjectContext projectContext = insertionPoint.SceneNode.ProjectContext;
            IType           type1          = projectContext.ResolveType((ITypeId)this.Type);
            IType           type2          = projectContext.GetType(type1.RuntimeAssembly.Name, type1.FullName) ?? projectContext.Platform.Metadata.GetType(type1.RuntimeType);

            if (type2 != null)
            {
                return(new DefaultTypeInstantiator(insertionPoint.SceneNode.ViewModel.DefaultView).CreatePrototypeInstance((ITypeId)type2));
            }
            return((SceneNode)null);
        }
Ejemplo n.º 5
0
 public ToolkitProjectContext(IProjectContext sourceContext)
     : base(sourceContext, (ICollection <IAssembly>)null)
 {
     this.CustomAssemblyReferences = (ICollection <IAssembly>) new List <IAssembly>();
     if (!sourceContext.PlatformMetadata.IsNullType((ITypeId)sourceContext.ResolveType(ProjectNeutralTypes.VisualStateManager)) || !sourceContext.IsCapabilitySet(PlatformCapability.VsmInToolkit))
     {
         return;
     }
     if (!sourceContext.IsCapabilitySet(PlatformCapability.SupportsVisualStateManager))
     {
         return;
     }
     try
     {
         Assembly assembly = ProjectAssemblyHelper.LoadFile(ToolkitHelper.GetToolkitPath());
         this.CustomAssemblyReferences = (ICollection <IAssembly>) new List <IAssembly>(1)
         {
             sourceContext.Platform.Metadata.CreateAssembly(assembly, AssemblySource.PlatformExtension)
         };
     }
     catch (Exception ex)
     {
     }
 }
Ejemplo n.º 6
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);
                    }
                }
            }
        }
Ejemplo n.º 7
0
 private static void EnsurePreloadKnownAttachedProperties(IAttachedPropertiesAccessToken token, IProjectContext project)
 {
     token.PreloadType(project.ResolveType(PlatformTypes.Canvas));
     token.PreloadType(project.ResolveType(PlatformTypes.Grid));
 }
Ejemplo n.º 8
0
        public override bool SupportsTextEditing(IProjectContext projectContext)
        {
            IType resolvedType = projectContext.ResolveType((ITypeId)this.Type);

            return(Enumerable.Any <ITypeId>(TextTool.TextToolTypes, (Func <ITypeId, bool>)(textType => textType.IsAssignableFrom((ITypeId)resolvedType))));
        }
Ejemplo n.º 9
0
        public static StyleNode CreateEmptyStyle(SceneViewModel sceneViewModel, IPropertyId propertyKey, ITypeId elementType)
        {
            IProperty       property       = sceneViewModel.ProjectContext.ResolveProperty(propertyKey);
            StyleNode       styleNode      = (StyleNode)sceneViewModel.CreateSceneNode(PlatformTypes.Style);
            IProjectContext projectContext = sceneViewModel.ProjectContext;
            Type            type1          = projectContext.MetadataFactory.GetMetadata(projectContext.ResolveType(elementType).RuntimeType).GetStylePropertyTargetType((IPropertyId)property);

            if (type1 == (Type)null && !projectContext.IsCapabilitySet(PlatformCapability.SupportsStyleWithoutTargetType))
            {
                type1 = projectContext.PlatformMetadata.ResolveType(PlatformTypes.FrameworkElement).RuntimeType;
            }
            if (type1 != (Type)null)
            {
                IType type2 = projectContext.GetType(type1);
                styleNode.StyleTargetTypeId = type2;
            }
            return(styleNode);
        }
        private void ResolveDefaultStyle(SceneElement targetElement, object defaultStyleKey, bool allowDefaultStyle, out DocumentNode currentStyle, out bool isThemeStyle, out IList <DocumentCompositeNode> auxillaryResources)
        {
            IProjectContext      projectContext1      = this.SceneViewModel.ProjectContext;
            ThemeContentProvider themeContentProvider = this.DesignerContext.ThemeContentProvider;

            currentStyle       = (DocumentNode)null;
            isThemeStyle       = false;
            auxillaryResources = (IList <DocumentCompositeNode>)null;
            if (defaultStyleKey == null)
            {
                return;
            }
            IAssembly runtimeAssembly = targetElement.Type.RuntimeAssembly;
            IAssembly targetAssembly  = PlatformTypeHelper.GetTargetAssembly(targetElement.Type);
            Type      type1           = defaultStyleKey as Type;

            if (type1 != (Type)null)
            {
                ITypeId typeId = (ITypeId)projectContext1.GetType(type1);
                if (typeId != null)
                {
                    IType type2 = projectContext1.ResolveType(typeId);
                    runtimeAssembly = type2.RuntimeAssembly;
                    targetAssembly  = PlatformTypeHelper.GetTargetAssembly(type2);
                }
            }
            IAssembly designAssembly = projectContext1.GetDesignAssembly(runtimeAssembly);

            if (designAssembly != null)
            {
                currentStyle = themeContentProvider.GetThemeResourceFromAssembly(projectContext1, designAssembly, designAssembly, defaultStyleKey, out auxillaryResources);
                if (currentStyle != null)
                {
                    return;
                }
            }
            if (!PlatformTypes.IsPlatformType((ITypeId)this.Type))
            {
                foreach (IProject project in this.DesignerContext.ProjectManager.CurrentSolution.Projects)
                {
                    IProjectContext projectContext2 = (IProjectContext)ProjectXamlContext.GetProjectContext(project);
                    if (projectContext2 != null && runtimeAssembly.Equals((object)projectContext2.ProjectAssembly))
                    {
                        currentStyle = themeContentProvider.GetThemeResourceFromProject(project, defaultStyleKey, out auxillaryResources);
                        if (currentStyle != null)
                        {
                            return;
                        }
                    }
                }
            }
            else if (!allowDefaultStyle || projectContext1.PlatformMetadata.TargetFramework.Identifier == ".NETFramework" && projectContext1.PlatformMetadata.TargetFramework.Version < projectContext1.PlatformMetadata.RuntimeFramework.Version)
            {
                currentStyle = themeContentProvider.GetThemeResourceFromPlatform(projectContext1.Platform, defaultStyleKey, out auxillaryResources);
                if (currentStyle != null)
                {
                    isThemeStyle = true;
                    return;
                }
            }
            if (!projectContext1.IsCapabilitySet(PlatformCapability.IsWpf))
            {
                currentStyle = themeContentProvider.GetThemeResourceFromAssembly(projectContext1, runtimeAssembly, targetAssembly, defaultStyleKey, out auxillaryResources);
                isThemeStyle = currentStyle != null;
            }
            else
            {
                object resource = this.SceneViewModel.FindResource(defaultStyleKey);
                if (resource == null)
                {
                    return;
                }
                if (projectContext1 != null && projectContext1.IsCapabilitySet(PlatformCapability.VsmInToolkit) && (projectContext1.IsCapabilitySet(PlatformCapability.SupportsVisualStateManager) && projectContext1.PlatformMetadata.IsNullType((ITypeId)projectContext1.ResolveType(ProjectNeutralTypes.VisualStateManager))))
                {
                    IAssembly usingAssemblyName = projectContext1.Platform.Metadata.GetPlatformAssemblyUsingAssemblyName(targetElement.Type.RuntimeAssembly);
                    if (usingAssemblyName == null || !AssemblyHelper.IsPlatformAssembly(usingAssemblyName))
                    {
                        IDocumentContext documentContext = (IDocumentContext) new DocumentContext((IProjectContext) new ToolkitProjectContext(projectContext1), ((DocumentContext)this.SceneViewModel.Document.DocumentContext).DocumentLocator);
                        DocumentNode     node            = documentContext.CreateNode(resource.GetType(), resource);
                        if (ProjectAttributeHelper.GetDefaultStateRecords(this.Type, (ITypeResolver)(documentContext.TypeResolver as ProjectContext)).Count > 0 || (DocumentCompositeNode)node.FindFirst(new Predicate <DocumentNode>(this.SelectVisualStateGroupPredicate)) != null)
                        {
                            ToolkitHelper.AddToolkitReferenceIfNeeded((ITypeResolver)projectContext1, this.DesignerContext.ViewUpdateManager);
                        }
                    }
                }
                SceneNode sceneNode = this.SceneViewModel.CreateSceneNode(resource);
                if (!PlatformTypes.Style.IsAssignableFrom((ITypeId)sceneNode.Type))
                {
                    return;
                }
                currentStyle = sceneNode.DocumentNode;
            }
        }