示例#1
0
        private static IEnumerable <ReferenceStep> GetPropertiesForSceneNode(SceneNode node)
        {
            TextRangeElement textRange = node as TextRangeElement;

            if (textRange != null)
            {
                foreach (IPropertyId propertyId in textRange.RangeProperties)
                {
                    DependencyPropertyReferenceStep dp = node.ProjectContext.ResolveProperty(propertyId) as DependencyPropertyReferenceStep;
                    if (dp != null)
                    {
                        yield return((ReferenceStep)dp);
                    }
                }
            }
            else
            {
                foreach (IProperty property in ITypeExtensions.GetProperties(PropertyMerger.GetTypeFromSceneNode(node), MemberAccessTypes.Public, true))
                {
                    ReferenceStep referenceStep = property as ReferenceStep;
                    if (referenceStep != null)
                    {
                        DependencyPropertyReferenceStep dependencyPropertyReferenceStep = referenceStep as DependencyPropertyReferenceStep;
                        if (dependencyPropertyReferenceStep == null || !dependencyPropertyReferenceStep.IsAttachable)
                        {
                            yield return(referenceStep);
                        }
                    }
                }
            }
        }
示例#2
0
 public PropertyReferenceProperty(ObjectSetBase objectSet, PropertyReference propertyReference, AttributeCollection attributes, PropertyValue parentValue, Type proxyType)
     : base(parentValue)
 {
     if (attributes == null)
     {
         DependencyPropertyReferenceStep propertyReferenceStep = propertyReference.LastStep as DependencyPropertyReferenceStep;
         if (propertyReferenceStep != null)
         {
             attributes = propertyReferenceStep.Attributes;
         }
     }
     this.proxyType         = proxyType;
     this.attributes        = attributes;
     this.objectSet         = objectSet;
     this.propertyReference = propertyReference;
     if (propertyReference.LastStep.IsAttachable)
     {
         this.SetName(propertyReference.LastStep.DeclaringType.Name + "." + propertyReference.LastStep.Name);
     }
     else
     {
         this.SetName(propertyReference.LastStep.Name);
     }
     this.InitializeConverter(base.get_PropertyName());
     this.InitializeValueEditorParameters();
     if (!JoltHelper.TypeHasEnumValues(this.PropertyTypeId))
     {
         return;
     }
     this.objectSet.DesignerContext.ProjectManager.ProjectOpened += new EventHandler <ProjectEventArgs>(this.ProjectManager_ProjectOpened);
 }
示例#3
0
        private void SetSetterValue(DependencyPropertyReferenceStep referenceStep, DocumentNode setterValue)
        {
            foreach (SceneNode sceneNode in (IEnumerable <SceneNode>) this.Setters)
            {
                SetterSceneNode setterSceneNode = sceneNode as SetterSceneNode;
                if (setterSceneNode != null && setterSceneNode.Property == referenceStep)
                {
                    if (setterValue != null)
                    {
                        ((DocumentCompositeNode)setterSceneNode.DocumentNode).Properties[SetterSceneNode.ValueProperty] = setterValue;
                        return;
                    }
                    this.Setters.Remove((SceneNode)setterSceneNode);
                    return;
                }
            }
            if (setterValue == null)
            {
                return;
            }
            SetterSceneNode setterSceneNode1 = (SetterSceneNode)this.ViewModel.CreateSceneNode(PlatformTypes.Setter);

            setterSceneNode1.Property = referenceStep;
            ((DocumentCompositeNode)setterSceneNode1.DocumentNode).Properties[SetterSceneNode.ValueProperty] = setterValue;
            this.Setters.Add((SceneNode)setterSceneNode1);
        }
示例#4
0
        public DocumentNode EvaluateTemplateBinding(DocumentNodePath nodePath, DocumentCompositeNode templateBindingNode)
        {
            DocumentNode documentNode = null;
            DependencyPropertyReferenceStep member = null;
            DocumentPrimitiveNode           item   = templateBindingNode.Properties[KnownProperties.TemplateBindingPropertyProperty] as DocumentPrimitiveNode;

            if (item != null)
            {
                DocumentNodeMemberValue value = item.Value as DocumentNodeMemberValue;
                if (value != null)
                {
                    member = value.Member as DependencyPropertyReferenceStep;
                }
            }
            if (member != null)
            {
                DocumentNodePath containerOwnerPath = nodePath.GetContainerOwnerPath();
                if (containerOwnerPath != null)
                {
                    documentNode = this.EvaluateProperty(containerOwnerPath, member);
                    if (documentNode == null)
                    {
                        DocumentCompositeNode containerNode = nodePath.ContainerNode as DocumentCompositeNode;
                        documentNode = this.EvaluateProperty(nodePath.GetPathInContainer(containerNode), member);
                    }
                }
            }
            return(documentNode);
        }
示例#5
0
        private static DocumentNode GetTemplateNode(SceneNode newElement, DocumentCompositeNode styleNode, out StyleNode styleElement)
        {
            DocumentCompositeNode documentCompositeNode1 = styleNode.Properties[DictionaryEntryNode.ValueProperty] as DocumentCompositeNode;
            SceneViewModel        viewModel = newElement.ViewModel.GetViewModel(documentCompositeNode1.DocumentRoot, false);

            if (viewModel == null)
            {
                styleElement = (StyleNode)null;
                return((DocumentNode)null);
            }
            styleElement = viewModel.GetSceneNode((DocumentNode)documentCompositeNode1) as StyleNode;
            DependencyPropertyReferenceStep propertyReferenceStep = (DependencyPropertyReferenceStep)newElement.ViewModel.ProjectContext.ResolveProperty(ControlElement.TemplateProperty);

            if (documentCompositeNode1 != null)
            {
                DocumentCompositeNode documentCompositeNode2 = documentCompositeNode1.Properties[StyleNode.SettersProperty] as DocumentCompositeNode;
                if (documentCompositeNode2 != null)
                {
                    foreach (DocumentNode documentNode1 in (IEnumerable <DocumentNode>)documentCompositeNode2.Children)
                    {
                        DocumentCompositeNode documentCompositeNode3 = documentNode1 as DocumentCompositeNode;
                        if (documentCompositeNode3 != null)
                        {
                            IMemberId    memberId      = (IMemberId)DocumentPrimitiveNode.GetValueAsMember(documentCompositeNode3.Properties[SetterSceneNode.PropertyProperty]);
                            DocumentNode documentNode2 = documentCompositeNode3.Properties[SetterSceneNode.ValueProperty];
                            if (memberId != null && documentNode2 != null && propertyReferenceStep.Equals((object)memberId))
                            {
                                return(documentNode2);
                            }
                        }
                    }
                }
            }
            return((DocumentNode)null);
        }
示例#6
0
        public static List <TargetedReferenceStep> GetPropertiesFromSelection(IEnumerable <SceneNode> selectedSceneNodes)
        {
            List <TargetedReferenceStep> properties         = new List <TargetedReferenceStep>();
            ProjectXamlContext           projectXamlContext = (ProjectXamlContext)Enumerable.First <SceneNode>(selectedSceneNodes).ProjectContext;

            PropertyMerger.GetMergedPropertiesForSelection(selectedSceneNodes, properties);
            PropertyMerger.ReferenceStepComparer referenceStepComparer = new PropertyMerger.ReferenceStepComparer();
            int count = properties.Count;

            using (IAttachedPropertiesAccessToken propertiesAccessToken = projectXamlContext.AttachedProperties.Access())
            {
                if (!projectXamlContext.AttachedProperties.IsFinished)
                {
                    projectXamlContext.AttachedProperties.FinishedScanning += new EventHandler(PropertyMerger.OnAttachedPropertiesFinishedScanning);
                }
                foreach (IAttachedPropertyMetadata propertyMetadata in propertiesAccessToken.AllAttachedProperties())
                {
                    IType type = projectXamlContext.GetType(propertyMetadata.OwnerType);
                    if (type != null)
                    {
                        DependencyPropertyReferenceStep propertyReferenceStep = type.GetMember(MemberType.AttachedProperty, propertyMetadata.Name, MemberAccessTypes.Public) as DependencyPropertyReferenceStep;
                        if (propertyReferenceStep != null)
                        {
                            TargetedReferenceStep targetedReferenceStep = new TargetedReferenceStep((ReferenceStep)propertyReferenceStep, propertyReferenceStep.DeclaringType);
                            if (properties.BinarySearch(0, count, targetedReferenceStep, (IComparer <TargetedReferenceStep>)referenceStepComparer) < 0)
                            {
                                properties.Add(targetedReferenceStep);
                            }
                        }
                    }
                }
            }
            return(properties);
        }
示例#7
0
        private static int ReferenceStepCompare(TargetedReferenceStep r1, TargetedReferenceStep r2)
        {
            if (r1 == r2)
            {
                return(0);
            }
            DependencyPropertyReferenceStep propertyReferenceStep1 = r1.ReferenceStep as DependencyPropertyReferenceStep;
            DependencyPropertyReferenceStep propertyReferenceStep2 = r2.ReferenceStep as DependencyPropertyReferenceStep;

            if (propertyReferenceStep1 != null && propertyReferenceStep2 != null && propertyReferenceStep1.DependencyProperty == propertyReferenceStep2.DependencyProperty)
            {
                return(0);
            }
            int num = string.Compare(r1.ReferenceStep.Name, r2.ReferenceStep.Name, StringComparison.Ordinal);

            if (num != 0)
            {
                return(num);
            }
            if (r1.ReferenceStep.PropertyType.Equals((object)r2.ReferenceStep.PropertyType) && r1.ReferenceStep.MemberType == r2.ReferenceStep.MemberType)
            {
                return(0);
            }
            return(string.Compare(r1.ReferenceStep.DeclaringType.UniqueName, r2.ReferenceStep.DeclaringType.UniqueName, StringComparison.Ordinal));
        }
 public TemplateBindablePropertyModel(DependencyPropertyReferenceStep referenceStep)
 {
     if (referenceStep == null)
     {
         throw new ArgumentNullException("referenceStep");
     }
     this.referenceStep = referenceStep;
 }
        protected virtual bool IsCommandProperty(ReferenceStep referenceStep)
        {
            DependencyPropertyReferenceStep propertyReferenceStep = referenceStep as DependencyPropertyReferenceStep;

            if (propertyReferenceStep != null)
            {
                return(propertyReferenceStep.ShouldSerialize);
            }
            return(true);
        }
示例#10
0
 private DocumentNode GetSetterValue(DependencyPropertyReferenceStep referenceStep)
 {
     foreach (SceneNode sceneNode in (IEnumerable <SceneNode>) this.Setters)
     {
         SetterSceneNode setterSceneNode = sceneNode as SetterSceneNode;
         if (setterSceneNode != null && setterSceneNode.Property == referenceStep)
         {
             return(((DocumentCompositeNode)setterSceneNode.DocumentNode).Properties[SetterSceneNode.ValueProperty]);
         }
     }
     return((DocumentNode)null);
 }
示例#11
0
 public static PropertyInformation FromDependencyProperty(DependencyProperty property, Type objectType, ITypeResolver typeResolver)
 {
     if (property != null)
     {
         DependencyPropertyReferenceStep referenceStep = DependencyPropertyReferenceStep.GetReferenceStep(typeResolver, objectType, property);
         if (referenceStep != null)
         {
             return(new PropertyInformation(referenceStep));
         }
     }
     return((PropertyInformation)null);
 }
示例#12
0
 public override DocumentPropertyNodeReferenceBase CreateLocalDocumentPropertyNodeReference(DocumentCompositeNode parent, IPropertyId propertyKey)
 {
     if (parent == this.DocumentNode && !this.ProjectContext.ResolveType(PlatformTypes.Style).RuntimeType.IsAssignableFrom(propertyKey.TargetType))
     {
         DependencyPropertyReferenceStep referenceStep = propertyKey as DependencyPropertyReferenceStep;
         if (referenceStep != null)
         {
             return((DocumentPropertyNodeReferenceBase) new StyleNode.StyleDocumentPropertyNodeReference(this, referenceStep));
         }
     }
     return(base.CreateLocalDocumentPropertyNodeReference(parent, propertyKey));
 }
示例#13
0
        public virtual void ApplyPropertyChange(DocumentNodeChange change)
        {
            if (!this.IsTextPropertyChange(change))
            {
                return;
            }
            DependencyPropertyReferenceStep propertyReferenceStep = change.PropertyKey as DependencyPropertyReferenceStep;

            if (propertyReferenceStep == null)
            {
                return;
            }
            this.CopyProperty(this.TextSource.DesignerContext.PlatformConverter.ConvertToWpfPropertyKey((IProperty)propertyReferenceStep));
        }
示例#14
0
        public override IEnumerable <object> GetAttributes(Type attributeType)
        {
            DependencyPropertyReferenceStep step = this.property as DependencyPropertyReferenceStep;

            if (step != null)
            {
                foreach (System.Attribute attribute in step.Attributes)
                {
                    if (attributeType.IsAssignableFrom(attribute.GetType()))
                    {
                        yield return((object)attribute);
                    }
                }
            }
        }
示例#15
0
        public virtual StyleNode ExpandDefaultStyle(IPropertyId propertyKey)
        {
            propertyKey = (IPropertyId)this.ProjectContext.ResolveProperty(propertyKey);
            if (this.IsSet(BaseFrameworkElement.StyleProperty) == PropertyState.Set)
            {
                return((StyleNode)null);
            }
            DocumentNode nodeForDefaultStyle = this.GetDocumentNodeForDefaultStyle(this.Type, propertyKey);
            StyleNode    styleNode1          = (StyleNode)null;

            if (nodeForDefaultStyle != null)
            {
                if (!StyleNode.IsReferenceValue(nodeForDefaultStyle))
                {
                    StyleNode styleNode2 = (StyleNode)this.ViewModel.GetSceneNode(nodeForDefaultStyle);
                    foreach (SetterSceneNode setter in (IEnumerable <SceneNode>)styleNode2.Setters)
                    {
                        DependencyPropertyReferenceStep property = setter.Property;
                        if (property != null && PlatformTypes.FrameworkTemplate.IsAssignableFrom((ITypeId)property.PropertyType))
                        {
                            this.ResolveTemplate(setter);
                        }
                    }
                    if (styleNode2.VisualTriggers != null)
                    {
                        foreach (TriggerBaseNode triggerBaseNode in (IEnumerable <TriggerBaseNode>)styleNode2.VisualTriggers)
                        {
                            BaseTriggerNode baseTriggerNode = triggerBaseNode as BaseTriggerNode;
                            if (baseTriggerNode != null)
                            {
                                foreach (SetterSceneNode setter in (IEnumerable <SceneNode>)baseTriggerNode.Setters)
                                {
                                    DependencyPropertyReferenceStep property = setter.Property;
                                    if (property != null && PlatformTypes.FrameworkTemplate.IsAssignableFrom((ITypeId)property.PropertyType))
                                    {
                                        this.ResolveTemplate(setter);
                                    }
                                }
                            }
                        }
                    }
                }
                styleNode1 = (StyleNode)this.ViewModel.GetSceneNode(nodeForDefaultStyle);
                using (this.ViewModel.ForceBaseValue())
                    this.SetValueAsSceneNode(propertyKey, (SceneNode)styleNode1);
            }
            return(styleNode1);
        }
        protected bool BindsTwoWayByDefault(SceneNode targetNode, ReferenceStep targetProperty)
        {
            DependencyPropertyReferenceStep propertyReferenceStep = targetProperty as DependencyPropertyReferenceStep;

            if (propertyReferenceStep == null)
            {
                return(false);
            }
            Type targetType = targetNode.TargetType;

            if (DocumentNodeUtilities.IsStyleOrTemplate(targetNode.Type))
            {
                targetType = DocumentNodeUtilities.GetStyleOrTemplateTargetType(targetNode.DocumentNode).RuntimeType;
            }
            return(propertyReferenceStep.BindsTwoWayByDefault(targetType));
        }
示例#17
0
        public static IEnumerable <PropertyInformation> GetPropertiesForType(Type objectType, ITypeResolver typeResolver)
        {
            IType type = typeResolver.GetType(objectType);

            if (type != null)
            {
                foreach (IProperty property in ITypeExtensions.GetProperties(type, MemberAccessTypes.PublicOrInternal, true))
                {
                    DependencyPropertyReferenceStep dependencyPropertyReferenceStep = property as DependencyPropertyReferenceStep;
                    if (dependencyPropertyReferenceStep != null)
                    {
                        yield return(new PropertyInformation(dependencyPropertyReferenceStep));
                    }
                }
            }
        }
示例#18
0
        public void ClearTextProperty(IProperty property)
        {
            DependencyPropertyReferenceStep propertyReferenceStep = (DependencyPropertyReferenceStep)this.TypeResolver.ResolveProperty(this.TextSource.DesignerContext.PlatformConverter.ConvertToWpfPropertyKey(property));
            DependencyPropertyReferenceStep shadowProperty        = DesignTimeProperties.GetShadowProperty((IProperty)propertyReferenceStep, (ITypeId)this.TextSource.Type);

            if (shadowProperty != null && DesignTimeProperties.UseShadowPropertyForInstanceBuilding(this.TypeResolver, (IPropertyId)shadowProperty))
            {
                propertyReferenceStep = shadowProperty;
            }
            DependencyProperty dependencyProperty = (DependencyProperty)propertyReferenceStep.DependencyProperty;

            foreach (TextElement textElement in (TextElementCollection <Block>)((FlowDocument)this.RichTextBox.Document.PlatformSpecificObject).Blocks)
            {
                this.ClearPropertyOnInlines(textElement, dependencyProperty);
            }
            ((DependencyObject)this.richTextBox.Document.PlatformSpecificObject).ClearValue(dependencyProperty);
        }
示例#19
0
        public static BindingModeInfo GetDefaultBindingMode(DocumentNode targetNode, IPropertyId targetProperty, DataSchemaNodePath schemaPath)
        {
            BindingMode      mode             = (BindingMode)targetNode.TypeResolver.GetCapabilityValue(PlatformCapability.DefaultBindingMode);
            BindingDirection bindingDirection = (BindingDirection)targetNode.TypeResolver.GetCapabilityValue(PlatformCapability.DefaultBindingDirection);
            DependencyPropertyReferenceStep propertyReferenceStep = targetNode.TypeResolver.ResolveProperty(targetProperty) as DependencyPropertyReferenceStep;
            bool flag = false;

            if (schemaPath != null)
            {
                if (schemaPath.Node.IsReadOnly)
                {
                    flag = true;
                }
                else if (schemaPath.Node == schemaPath.Schema.Root)
                {
                    flag = !DataContextHelper.IsDataContextProperty(targetNode, (IPropertyId)propertyReferenceStep);
                }
            }
            if (flag)
            {
                if (mode == BindingMode.Default && bindingDirection == BindingDirection.TwoWay && (propertyReferenceStep != null && propertyReferenceStep.BindsTwoWayByDefault(targetNode.Type.RuntimeType)))
                {
                    return(new BindingModeInfo(BindingMode.OneWay, false));
                }
                if (schemaPath.IsCollection)
                {
                    return(new BindingModeInfo(mode, true));
                }
                return(new BindingModeInfo(BindingMode.OneWay, false));
            }
            if (bindingDirection == BindingDirection.TwoWay)
            {
                return(new BindingModeInfo(mode, true));
            }
            IProperty property = targetNode.TypeResolver.ResolveProperty(targetProperty);

            if (property != null)
            {
                BindableAttribute bindableAttribute = property.Attributes[typeof(BindableAttribute)] as BindableAttribute;
                if (bindableAttribute != null && bindableAttribute.Direction == BindingDirection.TwoWay)
                {
                    return(new BindingModeInfo(BindingMode.TwoWay, false));
                }
            }
            return(new BindingModeInfo(mode, true));
        }
示例#20
0
        private static ReferenceStep FilterPropertyInternal(ITypeResolver typeResolver, IType typeId, ReferenceStep referenceStep)
        {
            ReferenceStep referenceStep1 = (ReferenceStep)null;
            MemberType    memberTypes    = MemberType.LocalProperty | MemberType.AttachedProperty | referenceStep.MemberType;
            DependencyPropertyReferenceStep referenceStep2 = referenceStep as DependencyPropertyReferenceStep;

            if (referenceStep2 != null)
            {
                referenceStep1 = (ReferenceStep)DependencyPropertyReferenceStep.GetReferenceStep(typeResolver, typeId.NearestResolvedType.RuntimeType, referenceStep2, memberTypes);
            }
            else if ((referenceStep.MemberType & MemberType.AttachedProperty) != MemberType.None && typeResolver.GetType(referenceStep.TargetType).IsAssignableFrom((ITypeId)typeId))
            {
                referenceStep1 = referenceStep;
            }
            if (referenceStep1 == null)
            {
                referenceStep1 = (ReferenceStep)typeId.GetMember(memberTypes, referenceStep.Name, TypeHelper.GetAllowableMemberAccess(typeResolver, typeId));
            }
            return(referenceStep1);
        }
示例#21
0
        protected void RecalculateTemplateBindableProperties()
        {
            this.templateBindableProperties.Clear();
            SceneNode[] objects = this.Objects;
            if (objects.Length != 1)
            {
                return;
            }
            SceneNode sceneNode = objects[0];

            if (sceneNode == null || sceneNode.StoryboardContainer == null || !typeof(ControlTemplateElement).IsAssignableFrom(sceneNode.StoryboardContainer.GetType()) || !sceneNode.Platform.Metadata.IsCapabilitySet(PlatformCapability.SupportNonFrameworkElementTemplateBinding) && !PlatformTypes.FrameworkElement.IsAssignableFrom((ITypeId)sceneNode.Type))
            {
                return;
            }
            Type targetElementType = sceneNode.StoryboardContainer.TargetElementType;

            if (!(targetElementType != (Type)null))
            {
                return;
            }
            IList <TargetedReferenceStep> mergedProperties = PropertyMerger.GetMergedProperties((IEnumerable <SceneNode>) new SceneNode[1]
            {
                sceneNode.ViewModel.CreateSceneNode(targetElementType)
            });
            IProjectContext projectContext = sceneNode.ProjectContext;

            foreach (TargetedReferenceStep targetedReferenceStep in (IEnumerable <TargetedReferenceStep>)mergedProperties)
            {
                DependencyPropertyReferenceStep referenceStep = targetedReferenceStep.ReferenceStep as DependencyPropertyReferenceStep;
                if (referenceStep != null)
                {
                    bool showReadOnly = true;
                    if (PropertyInspectorModel.IsPropertyBrowsable(objects, targetedReferenceStep, showReadOnly) && PropertyInspectorModel.IsAttachedPropertyBrowsable(objects, this.ObjectTypeId, targetedReferenceStep, (ITypeResolver)projectContext))
                    {
                        this.templateBindableProperties.Add(new TemplateBindablePropertyModel(referenceStep));
                    }
                }
            }
            this.templateBindableProperties.Sort((Comparison <TemplateBindablePropertyModel>)((left, right) => string.Compare(left.PropertyName, right.PropertyName, StringComparison.CurrentCulture)));
            this.OnPropertyChanged("TemplateBindableProperties");
        }
示例#22
0
        protected virtual void CopyProperty(IPropertyId propertyId)
        {
            DependencyPropertyReferenceStep propertyReferenceStep = this.TextSource.DesignerContext.DesignerDefaultPlatformService.DefaultPlatform.Metadata.ResolveProperty(propertyId) as DependencyPropertyReferenceStep;
            ReferenceStep referenceStep1 = PlatformTypes.IsExpressionInteractiveType(PlatformTypeHelper.GetDeclaringType((IMember)propertyReferenceStep)) ? (ReferenceStep)propertyReferenceStep : PlatformTypeHelper.GetProperty((ITypeResolver)this.TextSource.ProjectContext, (ITypeId)this.TextSource.Type, MemberType.LocalProperty, propertyReferenceStep.Name);

            if (referenceStep1 == null)
            {
                return;
            }
            object computedValueAsWpf = this.TextSource.GetComputedValueAsWpf((IPropertyId)referenceStep1);

            if (!this.TextSource.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
            {
                if (DesignTimeProperties.GetShadowProperty((IProperty)referenceStep1, (ITypeId)this.TextSource.Type) != null)
                {
                    for (SceneNode sceneNode = (SceneNode)this.TextSource; sceneNode != null; sceneNode = sceneNode.Parent)
                    {
                        IProperty property = PlatformTypes.IsExpressionInteractiveType(PlatformTypeHelper.GetDeclaringType((IMember)referenceStep1)) ? (IProperty)referenceStep1 : (IProperty)PlatformTypeHelper.GetProperty((ITypeResolver)this.TextSource.ProjectContext, (ITypeId)sceneNode.Type, MemberType.LocalProperty, referenceStep1.Name);
                        if (property != null && sceneNode.IsSet((IPropertyId)property) == PropertyState.Set)
                        {
                            computedValueAsWpf = sceneNode.GetComputedValueAsWpf((IPropertyId)property);
                            break;
                        }
                    }
                }
            }
            try
            {
                ReferenceStep referenceStep2 = referenceStep1;
                if (!this.TextSource.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
                {
                    referenceStep2 = (ReferenceStep)propertyReferenceStep;
                }
                referenceStep2.SetValue(this.EditingElement.PlatformSpecificObject, computedValueAsWpf);
            }
            catch
            {
            }
        }
示例#23
0
        protected static bool ShouldSkipProperty(ReferenceStep property, ICollection <IProperty> propertiesToSkip)
        {
            bool flag;

            if (property == null)
            {
                return(true);
            }
            DependencyPropertyReferenceStep dependencyPropertyReferenceStep = property as DependencyPropertyReferenceStep;

            using (IEnumerator <IProperty> enumerator = propertiesToSkip.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    IProperty current = enumerator.Current;
                    if (!current.Equals(property))
                    {
                        if (dependencyPropertyReferenceStep == null)
                        {
                            continue;
                        }
                        DependencyPropertyReferenceStep dependencyPropertyReferenceStep1 = current as DependencyPropertyReferenceStep;
                        if (dependencyPropertyReferenceStep1 == null || dependencyPropertyReferenceStep.DependencyProperty != dependencyPropertyReferenceStep1.DependencyProperty)
                        {
                            continue;
                        }
                        flag = true;
                        return(flag);
                    }
                    else
                    {
                        flag = true;
                        return(flag);
                    }
                }
                return(false);
            }
            return(flag);
        }
示例#24
0
 public XamlNameResolverImpl(object target, IMetadataResolver metadataResolver)
 {
     if (InstanceBuilderOperations.InstanceBuilderServiceProvider.XamlNameResolverImpl.DesignTimeNameScopeProperty == null)
     {
         DependencyPropertyReferenceStep dependencyPropertyReferenceStep = metadataResolver.ResolveProperty(DesignTimeProperties.DesignTimeNameScopeProperty) as DependencyPropertyReferenceStep;
         if (dependencyPropertyReferenceStep != null)
         {
             InstanceBuilderOperations.InstanceBuilderServiceProvider.XamlNameResolverImpl.DesignTimeNameScopeProperty = (DependencyProperty)dependencyPropertyReferenceStep.DependencyProperty;
         }
     }
     this.target = target;
     this.FindNameScope();
     UIThreadDispatcherHelper.BeginInvoke(DispatcherPriority.Send, new DispatcherOperationCallback((object o) => {
         this.isInitialized = true;
         this.FindNameScope();
         if (this.OnNameScopeInitializationComplete != null)
         {
             this.OnNameScopeInitializationComplete(this, EventArgs.Empty);
         }
         return(null);
     }), null);
 }
示例#25
0
        public static PathElement ConvertToPath(BaseFrameworkElement element)
        {
            SceneViewModel  viewModel        = element.ViewModel;
            PathGeometry    pathGeometry     = PathConversionHelper.ConvertToPathGeometry((SceneElement)element);
            PathElement     pathElement      = (PathElement)viewModel.CreateSceneNode(PlatformTypes.Path);
            ILayoutDesigner designerForChild = viewModel.GetLayoutDesignerForChild((SceneElement)element, true);
            Rect            childRect        = designerForChild.GetChildRect(element);
            Transform       transform1       = Transform.Identity;

            if (element.IsSet(Base2DElement.RenderTransformProperty) == PropertyState.Set)
            {
                transform1 = (Transform)element.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty);
            }
            Point point1 = new Point(0.5, 0.5);

            if (element.IsSet(Base2DElement.RenderTransformOriginProperty) == PropertyState.Set)
            {
                point1 = (Point)element.GetComputedValueAsWpf(Base2DElement.RenderTransformOriginProperty);
            }
            bool flag = false;

            using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.UndoUnitConvertToPath, true))
            {
                using (viewModel.ForceBaseValue())
                {
                    pathElement.PathGeometry = pathGeometry;
                    pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)Stretch.Fill);
                    Brush textForeground = PathCommandHelper.GetTextForeground(element);
                    if (textForeground != null)
                    {
                        flag = true;
                        pathElement.SetValueAsWpf(ShapeElement.FillProperty, (object)textForeground);
                    }
                    viewModel.AnimationEditor.DeleteAllAnimations((SceneNode)element);
                    Dictionary <IPropertyId, SceneNode> properties         = SceneElementHelper.StoreProperties((SceneNode)element);
                    ISceneNodeCollection <SceneNode>    collectionForChild = element.Parent.GetCollectionForChild((SceneNode)element);
                    int index = collectionForChild.IndexOf((SceneNode)element);
                    collectionForChild[index] = (SceneNode)pathElement;
                    if (flag)
                    {
                        List <IPropertyId> list = new List <IPropertyId>();
                        foreach (KeyValuePair <IPropertyId, SceneNode> keyValuePair in properties)
                        {
                            IPropertyId key = keyValuePair.Key;
                            DependencyPropertyReferenceStep propertyReferenceStep = key as DependencyPropertyReferenceStep;
                            if (propertyReferenceStep != null && !propertyReferenceStep.IsAttachable && (propertyReferenceStep.MemberType != MemberType.DesignTimeProperty && !PlatformTypeHelper.GetDeclaringType((IMember)propertyReferenceStep).IsAssignableFrom(typeof(Path))))
                            {
                                list.Add(key);
                            }
                        }
                        foreach (IPropertyId key in list)
                        {
                            properties.Remove(key);
                        }
                    }
                    SceneElementHelper.ApplyProperties((SceneNode)pathElement, properties);
                }
                if (ProjectNeutralTypes.PrimitiveShape.IsAssignableFrom((ITypeId)element.Type))
                {
                    using (viewModel.ForceBaseValue())
                    {
                        Rect   bounds          = pathGeometry.Bounds;
                        double halfStrokeWidth = PathCommandHelper.GetHalfStrokeWidth(pathElement);
                        bounds.Inflate(halfStrokeWidth / 2.0, halfStrokeWidth / 2.0);
                        if (transform1 != Transform.Identity && bounds.Size != childRect.Size)
                        {
                            Point point2 = (Point)pathElement.GetComputedValueAsWpf(Base2DElement.RenderTransformOriginProperty);
                            Point point3 = new Point(point2.X * childRect.Width, point2.Y * childRect.Height);
                            Point point4 = new Point((point3.X - bounds.X) / bounds.Width, (point3.Y - bounds.Y) / bounds.Height);
                            pathElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)point4);
                        }
                        bounds.Offset(childRect.Left, childRect.Top);
                        editTransaction.Update();
                        designerForChild.SetChildRect((BaseFrameworkElement)pathElement, bounds);
                    }
                }
                if (flag && !pathGeometry.IsEmpty())
                {
                    using (viewModel.ForceBaseValue())
                    {
                        Rect bounds = pathGeometry.Bounds;
                        bounds.Offset(childRect.Left, childRect.Top);
                        Point point2 = new Point(bounds.Left + point1.X * bounds.Width, bounds.Top + point1.Y * bounds.Height);
                        Point point3 = new Point(childRect.Left + childRect.Width * point1.X, childRect.Top + childRect.Height * point1.Y);
                        Point point4 = new TransformGroup()
                        {
                            Children =
                            {
                                (Transform) new TranslateTransform(-point3.X, -point3.Y),
                                transform1,
                                (Transform) new TranslateTransform(point3.X,  point3.Y)
                            }
                        }.Transform(point2);
                        Transform transform2 = (Transform) new CanonicalTransform(transform1)
                        {
                            TranslationX = 0.0,
                            TranslationY = 0.0
                        }.TransformGroup;
                        Rect rect = new Rect(point4.X - bounds.Width * point1.X, point4.Y - bounds.Height * point1.Y, bounds.Width, bounds.Height);
                        pathElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)point1);
                        editTransaction.Update();
                        designerForChild.SetChildRect((BaseFrameworkElement)pathElement, rect);
                        pathElement.RenderTransform = transform2;
                    }
                }
                editTransaction.Commit();
            }
            return(pathElement);
        }
示例#26
0
        private SerializedFormat ShouldSerializeProperty(XamlSerializerContext serializerContext, DocumentCompositeNode parentNode, IPropertyId propertyKey, DocumentNode valueNode, out bool useElementForOuterMostMarkupExtension)
        {
            bool             flag;
            SerializedFormat serializedFormat;

            useElementForOuterMostMarkupExtension = false;
            DocumentCompositeNode documentCompositeNode = valueNode as DocumentCompositeNode;
            DocumentPrimitiveNode documentPrimitiveNode = valueNode as DocumentPrimitiveNode;
            IProperty             valueProperty         = valueNode.GetValueProperty();

            if (valueProperty != null)
            {
                if (valueProperty.MemberType != MemberType.DesignTimeProperty && !this.ShouldSerialize(serializerContext, valueNode))
                {
                    return(SerializedFormat.DoNotSerialize);
                }
                if (valueProperty.MemberType == MemberType.DesignTimeProperty)
                {
                    bool flag1 = true;
                    if (!valueProperty.ShouldSerialize)
                    {
                        flag1 = this.ShouldSerializeDesignTimeProperty(valueProperty);
                    }
                    if (!flag1)
                    {
                        return(SerializedFormat.DoNotSerialize);
                    }
                }
                if (!KnownProperties.SetterTargetNameProperty.Equals(valueProperty))
                {
                    if (parentNode.Type.Metadata.IsNameProperty(valueProperty))
                    {
                        string valueAsString = DocumentPrimitiveNode.GetValueAsString(valueNode);
                        if (valueAsString != null)
                        {
                            if (valueAsString.StartsWith("~", StringComparison.Ordinal) && serializerContext.InStyleOrTemplate)
                            {
                                return(SerializedFormat.DoNotSerialize);
                            }
                            if (valueAsString.Length == 0)
                            {
                                return(SerializedFormat.DoNotSerialize);
                            }
                        }
                        return(SerializedFormat.ComplexString);
                    }
                    if (DesignTimeProperties.UidProperty.Equals(valueProperty))
                    {
                        return(SerializedFormat.ComplexString);
                    }
                    if (KnownProperties.FrameworkContentElementResourcesProperty.Equals(valueProperty))
                    {
                        if (documentCompositeNode != null && PlatformTypes.ResourceDictionary.IsAssignableFrom(documentCompositeNode.Type) && documentCompositeNode.SupportsChildren && documentCompositeNode.Children.Count == 0)
                        {
                            return(SerializedFormat.DoNotSerialize);
                        }
                    }
                    else if (!PlatformTypes.Style.IsAssignableFrom(valueProperty.PropertyType))
                    {
                        DependencyPropertyReferenceStep dependencyPropertyReferenceStep = valueProperty as DependencyPropertyReferenceStep;
                        if (dependencyPropertyReferenceStep != null && dependencyPropertyReferenceStep.IsAttachable && !DefaultXamlSerializerFilter.IsTypeSerializable(serializerContext.TypeResolver, valueProperty.DeclaringType) && dependencyPropertyReferenceStep.MemberType != MemberType.DesignTimeProperty)
                        {
                            return(SerializedFormat.DoNotSerialize);
                        }
                    }
                    else if (documentCompositeNode != null)
                    {
                        if (documentCompositeNode.GetValue <bool>(DesignTimeProperties.IsDefaultStyleProperty))
                        {
                            return(SerializedFormat.DoNotSerialize);
                        }
                    }
                    else if (documentPrimitiveNode != null && documentPrimitiveNode.Value is DocumentNodeReferenceValue)
                    {
                        return(SerializedFormat.DoNotSerialize);
                    }
                }
                else
                {
                    string str = DocumentPrimitiveNode.GetValueAsString(valueNode);
                    if (str != null && str == "~Self")
                    {
                        return(SerializedFormat.DoNotSerialize);
                    }
                }
            }
            IType type = valueNode.Type;

            if (PlatformTypes.XData.Equals(type))
            {
                return(SerializedFormat.Element);
            }
            if (PlatformTypes.StaticResource.IsAssignableFrom(type) && documentCompositeNode != null && ResourceNodeHelper.GetResourceKey(documentCompositeNode) != null)
            {
                DocumentCompositeNode parent = documentCompositeNode.Parent;
                while (parent != null && parent.Type.IsExpression)
                {
                    parent = parent.Parent;
                }
                if (parent != null)
                {
                    IPropertyId resourcesProperty = parent.Type.Metadata.ResourcesProperty;
                    if (resourcesProperty != null)
                    {
                        DocumentCompositeNode item = parent.Properties[resourcesProperty] as DocumentCompositeNode;
                        if (item != null && PlatformTypes.ResourceDictionary.IsAssignableFrom(item.Type))
                        {
                            useElementForOuterMostMarkupExtension = true;
                            return(SerializedFormat.ComplexString);
                        }
                    }
                }
            }
            if (type.IsExpression)
            {
                if (documentCompositeNode != null)
                {
                    using (IEnumerator <KeyValuePair <IProperty, DocumentNode> > enumerator = documentCompositeNode.Properties.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            KeyValuePair <IProperty, DocumentNode> current = enumerator.Current;
                            switch (this.ShouldSerializeProperty(serializerContext, documentCompositeNode, current.Key, current.Value, out flag))
                            {
                            case SerializedFormat.SimpleString:
                            {
                                continue;
                            }

                            case SerializedFormat.ComplexString:
                            {
                                if (current.Value.Type.IsExpression)
                                {
                                    if (!flag)
                                    {
                                        continue;
                                    }
                                    useElementForOuterMostMarkupExtension = true;
                                    continue;
                                }
                                else
                                {
                                    serializedFormat = SerializedFormat.Element;
                                    return(serializedFormat);
                                }
                            }
                            }
                            serializedFormat = SerializedFormat.Element;
                            return(serializedFormat);
                        }
                        return(SerializedFormat.ComplexString);
                    }
                    return(serializedFormat);
                }
                return(SerializedFormat.ComplexString);
            }
            if (this.PropertyValueRequiresElement(valueProperty, valueNode.Type))
            {
                return(SerializedFormat.Element);
            }
            if (PlatformTypes.Uri.IsAssignableFrom(type))
            {
                return(SerializedFormat.ComplexString);
            }
            if (PlatformTypes.PropertyPath.IsAssignableFrom(type))
            {
                if (documentCompositeNode != null)
                {
                    if (DocumentPrimitiveNode.GetValueAsString(documentCompositeNode.Properties[KnownProperties.PropertyPathPathProperty]) != null)
                    {
                        return(SerializedFormat.SimpleString);
                    }
                    return(SerializedFormat.Element);
                }
            }
            else if (PlatformTypes.SolidColorBrush.IsAssignableFrom(type))
            {
                if (documentCompositeNode != null)
                {
                    if (documentCompositeNode.Properties.Count == 0)
                    {
                        return(SerializedFormat.SimpleString);
                    }
                    if (documentCompositeNode.Properties.Count == 1)
                    {
                        DocumentPrimitiveNode item1 = documentCompositeNode.Properties[KnownProperties.SolidColorBrushColorProperty] as DocumentPrimitiveNode;
                        if (item1 != null && PlatformTypes.Color.Equals(item1.Type))
                        {
                            return(SerializedFormat.SimpleString);
                        }
                    }
                    return(SerializedFormat.Element);
                }
            }
            else if (!PlatformTypes.Color.IsAssignableFrom(type))
            {
                if (PlatformTypes.PathGeometry.IsAssignableFrom(type))
                {
                    if (valueProperty == null || PlatformTypes.PathGeometry.IsAssignableFrom(valueProperty.PropertyType))
                    {
                        return(SerializedFormat.Element);
                    }
                    if (documentCompositeNode != null && !PathGeometrySerializationHelper.CanSerializeAsAttribute(documentCompositeNode))
                    {
                        return(SerializedFormat.Element);
                    }
                    return(SerializedFormat.ComplexString);
                }
                if (PlatformTypes.PathFigureCollection.IsAssignableFrom(type))
                {
                    if (documentCompositeNode != null && !PathGeometrySerializationHelper.CanSerializeAsAttribute(documentCompositeNode))
                    {
                        return(SerializedFormat.Element);
                    }
                    return(SerializedFormat.ComplexString);
                }
                if (PlatformTypes.DoubleCollection.IsAssignableFrom(type))
                {
                    if (documentCompositeNode != null && PointSerializationHelper.SerializeDoubleCollectionAsAttribute(documentCompositeNode) == null)
                    {
                        return(SerializedFormat.Element);
                    }
                    return(SerializedFormat.ComplexString);
                }
            }
            else if (documentCompositeNode == null && valueNode.Parent != null && valueNode.IsProperty)
            {
                return(SerializedFormat.SimpleString);
            }
            if (documentPrimitiveNode != null && documentPrimitiveNode.Value == null)
            {
                return(SerializedFormat.SimpleString);
            }
            if (XamlSerializerContext.IsXmlElement(valueNode))
            {
                return(SerializedFormat.Element);
            }
            if (documentPrimitiveNode != null)
            {
                if (documentPrimitiveNode.Value is DocumentNodeStringValue)
                {
                    return(SerializedFormat.SimpleString);
                }
                if (documentPrimitiveNode.Value is DocumentNodeMemberValue)
                {
                    return(SerializedFormat.SimpleString);
                }
            }
            if (documentCompositeNode == null)
            {
                return(SerializedFormat.ComplexString);
            }
            return(SerializedFormat.Element);
        }
示例#27
0
        public override void Instantiate()
        {
            base.Instantiate();
            this.CopyProperty(RichTextBoxElement.VerticalScrollBarVisibilityProperty);
            this.CopyProperty(RichTextBoxElement.HorizontalScrollBarVisibilityProperty);
            this.CopyProperty(RichTextBoxRangeElement.TextBlockTextAlignmentPropertyId);
            if (this.TextSource.ProjectContext.ResolveProperty(RichTextBoxElement.CaretBrushProperty) != null)
            {
                this.CopyProperty(RichTextBoxElement.CaretBrushProperty);
            }
            ITextFlowSceneNode textFlowSceneNode = (ITextFlowSceneNode)this.TextSource;
            DocumentNodePath   documentNodePath  = this.TextSource.DocumentNodePath;
            SceneViewModel     viewModel         = this.TextSource.ViewModel;
            IDocumentContext   documentContext   = viewModel.Document.DocumentContext;
            IProjectContext    projectContext    = viewModel.Document.ProjectContext;

            using (InstanceBuilderContext instanceBuilderContext = new InstanceBuilderContext(projectContext, viewModel, true, (Microsoft.Expression.DesignModel.DocumentModel.DocumentNode)null))
            {
                using (instanceBuilderContext.DisablePostponedResourceEvaluation())
                {
                    instanceBuilderContext.ViewNodeManager.RootNodePath = documentNodePath;
                    instanceBuilderContext.ViewNodeManager.Instantiate(instanceBuilderContext.ViewNodeManager.Root);
                }
                this.UpdateUIChildrenInstances((IInstanceBuilderContext)instanceBuilderContext);
                ReferenceStep referenceStep = (ReferenceStep)projectContext.ResolveProperty(textFlowSceneNode.TextChildProperty);
                bool          flag1         = false;
                bool          flag2         = false;
                bool          flag3         = false;
                FlowDocument  flowDocument  = (FlowDocument)referenceStep.GetCurrentValue(instanceBuilderContext.ViewNodeManager.Root.Instance);
                DependencyPropertyReferenceStep shadowProperty = DesignTimeProperties.GetShadowProperty(projectContext.ResolveProperty(TextElementSceneElement.FontFamilyProperty), (ITypeId)null);
                if (flowDocument == null)
                {
                    flowDocument = new FlowDocument();
                }
                else
                {
                    flag1 = ((ReferenceStep)projectContext.ResolveProperty(TextElementSceneElement.FontSizeProperty)).IsSet((object)flowDocument);
                    flag2 = ((ReferenceStep)projectContext.ResolveProperty(ParagraphElement.TextAlignmentProperty)).IsSet((object)flowDocument);
                    flag3 = shadowProperty.IsSet((object)flowDocument);
                }
                double        fontSize      = flowDocument.FontSize;
                FontFamily    fontFamily    = (FontFamily)shadowProperty.GetValue((object)flowDocument);
                Thickness     pagePadding   = flowDocument.PagePadding;
                TextAlignment textAlignment = flowDocument.TextAlignment;
                referenceStep.SetValue(instanceBuilderContext.ViewNodeManager.Root.Instance, (object)new FlowDocument());
                this.RichTextBox.Document = (IViewFlowDocument)this.TextSource.Platform.ViewObjectFactory.Instantiate((object)flowDocument);
                if (flag1)
                {
                    flowDocument.FontSize = fontSize;
                }
                if (flag3)
                {
                    if (!DesignTimeProperties.UseShadowPropertyForInstanceBuilding(this.TypeResolver, ControlElement.FontFamilyProperty))
                    {
                        flowDocument.FontFamily = fontFamily;
                    }
                    else
                    {
                        shadowProperty.SetValue((object)flowDocument, (object)fontFamily);
                    }
                }
                if (flag2)
                {
                    flowDocument.TextAlignment = textAlignment;
                }
                flowDocument.PagePadding = pagePadding;
            }
        }
示例#28
0
        public override void Execute()
        {
            BaseFrameworkElement selectedElement = this.SelectedElement;

            if (selectedElement == null)
            {
                return;
            }
            IType type1 = this.SceneViewModel.ProjectContext.ResolveType(PlatformTypes.Style);

            CreateResourceModel.ContextFlags contextFlags = this.SceneViewModel.ProjectContext.IsCapabilitySet(PlatformCapability.SupportsImplicitStyles) ? CreateResourceModel.ContextFlags.CanApplyAutomatically : CreateResourceModel.ContextFlags.None;
            if (this.SceneViewModel.ProjectContext.IsCapabilitySet(PlatformCapability.SupportsImplicitStyles))
            {
                contextFlags = CreateResourceModel.ContextFlags.CanApplyAutomatically;
            }
            CreateResourceModel createResourceModel = new CreateResourceModel(this.SceneViewModel, this.DesignerContext.ResourceManager, type1.RuntimeType, this.DefaultContainerType.RuntimeType, PlatformTypes.Style.Name, (SceneElement)null, (SceneNode)selectedElement, contextFlags);

            if (this.ShowUI)
            {
                bool?nullable = this.CreateDialog(createResourceModel).ShowDialog();
                if ((!nullable.GetValueOrDefault() ? 1 : (!nullable.HasValue ? true : false)) != 0)
                {
                    return;
                }
            }
            using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove())
            {
                using (SceneEditTransaction editTransaction1 = this.SceneViewModel.CreateEditTransaction(this.UndoString, false))
                {
                    using (this.SceneViewModel.ForceBaseValue())
                    {
                        using (this.SceneViewModel.DisableDrawIntoState())
                        {
                            this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree((SceneElement)selectedElement);
                            this.SceneViewModel.ElementSelectionSet.Clear();
                            IDocumentContext documentContext = this.SceneViewModel.Document.DocumentContext;
                            IProjectContext  projectContext  = this.SceneViewModel.Document.ProjectContext;
                            Type             type2           = (Type)null;
                            if (createResourceModel.TargetTypeAsset != null && createResourceModel.TargetTypeAsset.EnsureTypeReferenced(this.SceneViewModel.ProjectContext as ProjectContext))
                            {
                                type2 = createResourceModel.TargetTypeAsset.Type.RuntimeType;
                            }
                            if (type2 == (Type)null)
                            {
                                type2 = createResourceModel.TargetType;
                            }
                            IType type3 = projectContext.GetType(type2);
                            DocumentCompositeNode documentCompositeNode1 = (DocumentCompositeNode)selectedElement.DocumentNode;
                            this.SceneViewModel.GetLayoutDesignerForChild((SceneElement)selectedElement, true).ClearUnusedLayoutProperties(selectedElement);
                            DocumentCompositeNode visualTreeNode            = documentContext.CreateNode((ITypeId)documentCompositeNode1.Type);
                            Dictionary <IProperty, DocumentNode> dictionary = new Dictionary <IProperty, DocumentNode>();
                            bool addRenderTransforms = false;
                            foreach (IPropertyId propertyId in this.GetLayoutProperties((SceneElement)selectedElement, addRenderTransforms))
                            {
                                IProperty property = this.DesignerContext.ActiveSceneViewModel.ProjectContext.ResolveProperty(propertyId);
                                if (property != null && documentCompositeNode1.Properties.Contains(property))
                                {
                                    dictionary.Add(property, documentCompositeNode1.Properties[(IPropertyId)property].Clone(documentContext));
                                    documentCompositeNode1.ClearValue((IPropertyId)property);
                                }
                            }
                            foreach (KeyValuePair <IProperty, DocumentNode> keyValuePair in (IEnumerable <KeyValuePair <IProperty, DocumentNode> >)documentCompositeNode1.Properties)
                            {
                                IPropertyId index = (IPropertyId)keyValuePair.Key;
                                DependencyPropertyReferenceStep propertyReferenceStep = index as DependencyPropertyReferenceStep;
                                if ((propertyReferenceStep == null || !propertyReferenceStep.IsAttachable || propertyReferenceStep.MemberType == MemberType.DesignTimeProperty) && (!index.Equals((object)BaseFrameworkElement.WidthProperty) && !index.Equals((object)BaseFrameworkElement.HeightProperty)))
                                {
                                    visualTreeNode.Properties[index] = keyValuePair.Value.Clone(documentContext);
                                }
                            }
                            if (documentCompositeNode1.SupportsChildren)
                            {
                                foreach (DocumentNode documentNode in (IEnumerable <DocumentNode>)documentCompositeNode1.Children)
                                {
                                    visualTreeNode.Children.Add(documentNode.Clone(documentContext));
                                }
                            }
                            if (!PlatformTypes.Panel.IsAssignableFrom((ITypeId)documentCompositeNode1.Type))
                            {
                                GridElement gridElement = (GridElement)this.SceneViewModel.CreateSceneNode(PlatformTypes.Grid);
                                SceneNode   sceneNode   = this.SceneViewModel.GetSceneNode((DocumentNode)visualTreeNode);
                                gridElement.Children.Add(sceneNode);
                                visualTreeNode = (DocumentCompositeNode)gridElement.DocumentNode;
                            }
                            StyleNode styleNode = (StyleNode)this.SceneViewModel.CreateSceneNode(PlatformTypes.Style);
                            styleNode.StyleTargetTypeId = type3;
                            SetterSceneNode setterSceneNode = (SetterSceneNode)this.SceneViewModel.CreateSceneNode(PlatformTypes.Setter);
                            DependencyPropertyReferenceStep propertyReferenceStep1 = (DependencyPropertyReferenceStep)this.SceneViewModel.ProjectContext.ResolveProperty(ControlElement.TemplateProperty);
                            setterSceneNode.Property = propertyReferenceStep1;
                            BaseFrameworkElement  frameworkElement       = (BaseFrameworkElement)this.SceneViewModel.CreateSceneNode(type2);
                            DocumentCompositeNode documentCompositeNode2 = (DocumentCompositeNode)frameworkElement.DocumentNode;
                            this.AddPresenterIfNecessary(visualTreeNode, (SceneElement)frameworkElement);
                            ControlTemplateElement controlTemplateElement = (ControlTemplateElement)this.SceneViewModel.CreateSceneNode(PlatformTypes.ControlTemplate);
                            controlTemplateElement.ControlTemplateTargetTypeId = (ITypeId)type3;
                            controlTemplateElement.DefaultInsertionPoint.Insert(this.SceneViewModel.GetSceneNode((DocumentNode)visualTreeNode));
                            if (PlatformTypes.Button.Equals((object)type3) && controlTemplateElement.CanEditTriggers && this.SceneViewModel.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
                            {
                                DocumentCompositeNode node = documentContext.CreateNode(typeof(TriggerCollection));
                                node.Children.Add((DocumentNode)this.CreatePropertyTrigger(documentContext, ButtonProperties.IsFocusedProperty, (object)true));
                                node.Children.Add((DocumentNode)this.CreatePropertyTrigger(documentContext, ButtonProperties.IsDefaultedProperty, (object)true));
                                node.Children.Add((DocumentNode)this.CreatePropertyTrigger(documentContext, BaseFrameworkElement.IsMouseOverProperty, (object)true));
                                node.Children.Add((DocumentNode)this.CreatePropertyTrigger(documentContext, ButtonProperties.IsPressedProperty, (object)true));
                                node.Children.Add((DocumentNode)this.CreatePropertyTrigger(documentContext, BaseFrameworkElement.IsEnabledProperty, (object)false));
                                controlTemplateElement.SetLocalValue(ControlTemplateElement.ControlTemplateTriggersProperty, (DocumentNode)node);
                            }
                            setterSceneNode.SetValueAsSceneNode(SetterSceneNode.ValueProperty, (SceneNode)controlTemplateElement);
                            styleNode.Setters.Add((SceneNode)setterSceneNode);
                            bool useStaticResource = !JoltHelper.TypeSupported((ITypeResolver)this.SceneViewModel.ProjectContext, PlatformTypes.DynamicResource);
                            int  index1            = -1;
                            if (useStaticResource && selectedElement.DocumentContext == createResourceModel.CurrentResourceSite.DocumentContext)
                            {
                                index1 = createResourceModel.IndexInResourceSite(selectedElement.DocumentNode);
                            }
                            IList <DocumentCompositeNode> referencedResources = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindReferencedResources((DocumentNode)documentCompositeNode1);
                            foreach (KeyValuePair <IProperty, DocumentNode> keyValuePair in dictionary)
                            {
                                documentCompositeNode2.Properties[(IPropertyId)keyValuePair.Key] = keyValuePair.Value;
                            }
                            IList <SceneNode> nodes = (IList <SceneNode>) new List <SceneNode>();
                            nodes.Add((SceneNode)frameworkElement);
                            SceneNode parent           = selectedElement.Parent;
                            IProperty propertyForChild = parent.GetPropertyForChild((SceneNode)selectedElement);
                            ISceneNodeCollection <SceneNode> collectionForProperty = parent.GetCollectionForProperty((IPropertyId)propertyForChild);
                            int index2 = collectionForProperty.IndexOf((SceneNode)selectedElement);
                            collectionForProperty[index2] = (SceneNode)frameworkElement;
                            if (createResourceModel.SelectedResourceDictionary != null)
                            {
                                ResourceContainer instance = createResourceModel.SelectedResourceDictionary.Instance;
                                if (instance != null && instance.DocumentNode == documentCompositeNode1)
                                {
                                    createResourceModel = new CreateResourceModel(this.SceneViewModel, this.DesignerContext.ResourceManager, type1.RuntimeType, type2, PlatformTypes.Style.Name, (SceneElement)frameworkElement, (SceneNode)null, contextFlags);
                                }
                            }
                            if (createResourceModel.CurrentResourceSite != null && !PlatformTypes.PlatformsCompatible(createResourceModel.CurrentResourceSite.DocumentContext.TypeResolver.PlatformMetadata, styleNode.DocumentNode.PlatformMetadata))
                            {
                                editTransaction1.Cancel();
                                return;
                            }
                            DocumentCompositeNode resource = createResourceModel.CreateResource(styleNode.DocumentNode, StyleNode.TargetTypeProperty, index1);
                            if (resource == null)
                            {
                                editTransaction1.Cancel();
                                return;
                            }
                            DocumentNode            resourceReference = createResourceModel.CreateResourceReference(this.SceneViewModel.Document.DocumentContext, resource, useStaticResource);
                            DefaultTypeInstantiator typeInstantiator  = new DefaultTypeInstantiator(this.SceneView);
                            if (resourceReference != null)
                            {
                                documentCompositeNode2.Properties[BaseFrameworkElement.StyleProperty] = resourceReference;
                            }
                            foreach (KeyValuePair <IProperty, DocumentNode> keyValuePair in (IEnumerable <KeyValuePair <IProperty, DocumentNode> >)documentCompositeNode1.Properties)
                            {
                                IPropertyId index3 = (IPropertyId)keyValuePair.Key;
                                DependencyPropertyReferenceStep propertyReferenceStep2 = index3 as DependencyPropertyReferenceStep;
                                if (propertyReferenceStep2 != null && propertyReferenceStep2.IsAttachable && propertyReferenceStep2.MemberType != MemberType.DesignTimeProperty)
                                {
                                    documentCompositeNode2.Properties[index3] = keyValuePair.Value.Clone(documentContext);
                                }
                            }
                            DocumentCompositeNode hostNode  = createResourceModel.CurrentResourceSite.HostNode;
                            SceneViewModel        viewModel = this.SceneViewModel.GetViewModel(hostNode.DocumentRoot, false);
                            using (SceneEditTransaction editTransaction2 = viewModel.CreateEditTransaction(this.UndoString))
                            {
                                Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CopyResourcesToNewResourceSite(referencedResources, viewModel, hostNode, resource, createResourceModel.IndexInResourceSite((DocumentNode)resource));
                                editTransaction2.Commit();
                            }
                            editTransaction1.Update();
                            if (this.SceneView.IsValid)
                            {
                                typeInstantiator.ApplyAfterInsertionDefaultsToElements(nodes, (SceneNode)null);
                            }
                            this.SceneView.CandidateEditingContainer = frameworkElement.DocumentNodePath;
                            editTransaction1.Update();
                            this.SceneViewModel.ElementSelectionSet.ExtendSelection((SceneElement)frameworkElement);
                            this.PostProcessing((SceneNode)selectedElement, (SceneNode)frameworkElement, resource);
                            if (frameworkElement.GetComputedValue(ControlElement.TemplateProperty) != null)
                            {
                                this.ActivateTemplateEditingMode((SceneElement)frameworkElement);
                            }
                            else
                            {
                                UIThreadDispatcherHelper.BeginInvoke(DispatcherPriority.ApplicationIdle, (Delegate) new Action <SceneElement>(this.ActivateTemplateEditingMode), (object)frameworkElement);
                            }
                            this.SceneView.CandidateEditingContainer = (DocumentNodePath)null;
                        }
                        editTransaction1.Commit();
                    }
                }
            }
        }
示例#29
0
        public static bool SetValue(object target, IProperty propertyKey, object value)
        {
            if (!InstanceBuilderOperations.IsSupported((IMember)propertyKey))
            {
                return(false);
            }
            if (DesignTimeProperties.InlineXmlProperty.Equals((object)propertyKey))
            {
                IXmlSerializable serializable = target as IXmlSerializable;
                if (serializable == null)
                {
                    return(false);
                }
                InstanceBuilderOperations.SetXmlContent(serializable, (string)value);
                return(true);
            }
            DocumentCompositeNode documentCompositeNode = target as DocumentCompositeNode;

            if (documentCompositeNode != null)
            {
                IProperty property = (IProperty)propertyKey.Clone(documentCompositeNode.TypeResolver);
                documentCompositeNode.Properties[(IPropertyId)property] = (DocumentNode)value;
                return(true);
            }
            ReferenceStep referenceStep = propertyKey as ReferenceStep;

            if (referenceStep != null)
            {
                object          obj = value;
                MarkupExtension markupExtension;
                if ((markupExtension = obj as MarkupExtension) != null)
                {
                    if (markupExtension is TemplateBindingExtension)
                    {
                        throw new InstanceBuilderException(ExceptionStringTable.InvalidTemplateBindingInstanceBuilderException);
                    }
                    DependencyPropertyReferenceStep propertyReferenceStep1;
                    object property;
                    if ((propertyReferenceStep1 = referenceStep as DependencyPropertyReferenceStep) != null)
                    {
                        property = propertyReferenceStep1.DependencyProperty;
                    }
                    else
                    {
                        ClrPropertyReferenceStep propertyReferenceStep2;
                        if ((propertyReferenceStep2 = referenceStep as ClrPropertyReferenceStep) == null)
                        {
                            return(false);
                        }
                        property = (object)propertyReferenceStep2.PropertyInfo;
                    }
                    DynamicResourceExtension resourceExtension       = markupExtension as DynamicResourceExtension;
                    FrameworkElement         frameworkElement        = target as FrameworkElement;
                    FrameworkContentElement  frameworkContentElement = target as FrameworkContentElement;
                    if (resourceExtension != null && resourceExtension.ResourceKey != null && propertyReferenceStep1 != null && (frameworkElement != null || frameworkContentElement != null))
                    {
                        if (frameworkElement != null)
                        {
                            propertyReferenceStep1.SetResourceReference((object)frameworkElement, resourceExtension.ResourceKey);
                        }
                        else if (frameworkContentElement != null)
                        {
                            propertyReferenceStep1.SetResourceReference((object)frameworkContentElement, resourceExtension.ResourceKey);
                        }
                    }
                    else
                    {
                        if (Microsoft.Expression.DesignModel.Metadata.KnownProperties.SetterValueProperty.Equals((object)referenceStep))
                        {
                            referenceStep.SetValue(target, obj);
                            return(true);
                        }
                        bool flag = false;
                        try
                        {
                            obj  = markupExtension.ProvideValue((IServiceProvider) new InstanceBuilderOperations.InstanceBuilderServiceProvider(target, property, (IMetadataResolver)referenceStep.DeclaringType.PlatformMetadata));
                            flag = true;
                        }
                        catch (InvalidOperationException ex)
                        {
                        }
                        if (flag)
                        {
                            if (!(obj is MarkupExtension))
                            {
                                return(InstanceBuilderOperations.SetValue(target, (IProperty)referenceStep, obj));
                            }
                            referenceStep.SetValue(target, obj);
                            return(true);
                        }
                    }
                }
                else
                {
                    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                    //if (obj is Expression)
                    //{
                    //    referenceStep.SetValue(target, obj);
                    //    return true;
                    //}
                    if (obj != null)
                    {
                        bool flag = false;
                        DependencyPropertyReferenceStep propertyReferenceStep = referenceStep as DependencyPropertyReferenceStep;
                        if (propertyReferenceStep != null)
                        {
                            ITypeId type = (ITypeId)propertyReferenceStep.PlatformTypes.GetType(obj.GetType());
                            if (PlatformTypes.Binding.IsAssignableFrom(type))
                            {
                                flag = true;
                            }
                        }
                        if (flag)
                        {
                            propertyReferenceStep.SetBinding(target, value);
                            return(true);
                        }
                        if (!PlatformTypeHelper.GetPropertyType((IProperty)referenceStep).IsInstanceOfType(obj))
                        {
                            return(false);
                        }
                    }
                    referenceStep.SetValue(target, obj);
                    return(true);
                }
            }
            return(false);
        }
示例#30
0
 public PropertyInformation(DependencyPropertyReferenceStep referenceStep)
 {
     this.referenceStep = referenceStep;
 }