Exemplo n.º 1
0
        private static void RunDesignModeValueProvider(object target, IPlatform platform, ValueTranslationService valueTranslationService, IType type, Type runtimeType, PropertyIdentifier property, ReferenceStep referenceStep, bool isFirstTime)
        {
            if (!runtimeType.IsAssignableFrom(target.GetType()))
            {
                return;
            }
            ModelItem modelItemForObject = DesignModeValueProviderService.GetModelItemForObject(platform, target);

            if (modelItemForObject == null)
            {
                return;
            }
            ReferenceStep referenceStep1 = (ReferenceStep)DesignTimeProperties.GetShadowProperty((IProperty)referenceStep, (ITypeId)type);

            try
            {
                object valueToSet;
                if (isFirstTime && !referenceStep1.IsSet(target))
                {
                    valueToSet = referenceStep.GetValue(target);
                    referenceStep1.SetValue(target, valueToSet);
                }
                else
                {
                    valueToSet = referenceStep1.GetValue(target);
                }
                referenceStep.SetValue(target, valueTranslationService.TranslatePropertyValue(runtimeType, modelItemForObject, property, valueToSet));
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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
            {
            }
        }
Exemplo n.º 4
0
 public void OnInitialized(IInstanceBuilderContext context, ViewNode target, object instance)
 {
     if (instance != null && this.targetType.IsAssignableFrom(instance.GetType()))
     {
         ITypeResolver typeResolver = target.DocumentNode.TypeResolver;
         IPlatform     platform     = context.Platform;
         platform.ViewObjectFactory.Instantiate(instance).SetValue(typeResolver, typeResolver.ResolveProperty(DesignTimeProperties.InstanceBuilderContextProperty), (object)new WeakReference((object)context));
         IDesignModeValueProviderContext valueProviderContext = context as IDesignModeValueProviderContext;
         if (valueProviderContext != null)
         {
             ValueTranslationService valueTranslationService = valueProviderContext.ValueTranslationService;
             foreach (PropertyIdentifier identifier in valueTranslationService.GetProperties(this.targetType))
             {
                 if (valueTranslationService.HasValueTranslation(this.targetType, identifier))
                 {
                     ReferenceStep referenceStep = target.Type.GetMember(MemberType.Property, identifier.Name, MemberAccessTypes.All) as ReferenceStep;
                     if (referenceStep != null)
                     {
                         if (!target.Properties.ContainsKey((IProperty)referenceStep))
                         {
                             ReferenceStep referenceStep1 = (ReferenceStep)DesignTimeProperties.GetShadowProperty((IProperty)referenceStep, (ITypeId)target.Type);
                             object        valueToSet     = referenceStep.GetValue(instance);
                             if (typeResolver.IsCapabilitySet(PlatformCapability.IsWpf) || valueToSet != null)
                             {
                                 referenceStep1.SetValue(instance, valueToSet);
                             }
                         }
                         PropertyIdentifier localProperty = identifier;
                         UIThreadDispatcherHelper.BeginInvoke(DispatcherPriority.Send, (Delegate)(o =>
                         {
                             if (target.Parent != null)
                             {
                                 DesignModeValueProviderService.RunDesignModeValueProvider(instance, platform, valueTranslationService, target.Type, this.targetType, localProperty, referenceStep, true);
                             }
                             return((object)null);
                         }), (object)null);
                     }
                 }
             }
         }
     }
     if (!context.IsSerializationScope)
     {
         return;
     }
     this.builder.OnInitialized(context, target, instance);
 }
Exemplo n.º 5
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;
            }
        }
        public override void ModifyValue(IInstanceBuilderContext context, ViewNode target, object onlyThisInstance, IProperty propertyKey, object value, PropertyModification modification)
        {
            IProperty shadowProperty;

            if (!context.IsSerializationScope)
            {
                IInstantiatedElementViewNode instantiatedElementViewNode = target as IInstantiatedElementViewNode;
                if (instantiatedElementViewNode != null && onlyThisInstance == null && instantiatedElementViewNode.InstantiatedElements.First != null)
                {
                    if (context.UseShadowProperties)
                    {
                        shadowProperty = DesignTimeProperties.GetShadowProperty(propertyKey, target.DocumentNode.Type);
                    }
                    else
                    {
                        shadowProperty = null;
                    }
                    IProperty property = shadowProperty;
                    if (property != null && DesignTimeProperties.UseShadowPropertyForInstanceBuilding(target.TypeResolver, property))
                    {
                        propertyKey = property;
                    }
                    ReferenceStep referenceStep = propertyKey as ReferenceStep;
                    if (referenceStep != null)
                    {
                        foreach (object instantiatedElement in instantiatedElementViewNode.InstantiatedElements)
                        {
                            if (modification != PropertyModification.Set)
                            {
                                referenceStep.ClearValue(instantiatedElement);
                            }
                            else
                            {
                                InstanceBuilderOperations.SetValue(instantiatedElement, referenceStep, value);
                            }
                        }
                        return;
                    }
                }
            }
            if (propertyKey.DeclaringType.Metadata.IsNameProperty(propertyKey))
            {
                string valueAsString = null;
                if (context.IsSerializationScope)
                {
                    DocumentPrimitiveNode documentPrimitiveNode = value as DocumentPrimitiveNode;
                    if (documentPrimitiveNode != null)
                    {
                        valueAsString = DocumentPrimitiveNode.GetValueAsString(documentPrimitiveNode);
                    }
                }
                else
                {
                    valueAsString = value as string;
                    if (string.IsNullOrEmpty(valueAsString) && (ProjectNeutralTypes.VisualStateGroup.IsAssignableFrom(target.Type) || ProjectNeutralTypes.VisualState.IsAssignableFrom(target.Type)))
                    {
                        valueAsString = ((DocumentCompositeNode)target.DocumentNode).GetValueAsString(target.DocumentNode.NameProperty);
                    }
                }
                if (valueAsString != null && string.IsNullOrEmpty(valueAsString))
                {
                    CultureInfo currentCulture = CultureInfo.CurrentCulture;
                    string      instanceBuilderNamePropertyNotValid = ExceptionStringTable.InstanceBuilderNamePropertyNotValid;
                    object[]    objArray = new object[] { valueAsString };
                    throw new InstanceBuilderException(string.Format(currentCulture, instanceBuilderNamePropertyNotValid, objArray), target.DocumentNode);
                }
            }
            base.ModifyValue(context, target, onlyThisInstance, propertyKey, value, modification);
        }
        public override void UpdateProperty(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode)
        {
            string        instance;
            string        str;
            IPropertyId   shadowProperty;
            ReferenceStep referenceStep = propertyKey as ReferenceStep;
            ViewNode      item          = viewNode.Properties[propertyKey];

            if (item != null && DocumentNodeUtilities.IsBinding(item.DocumentNode) && referenceStep != null)
            {
                ReferenceStep referenceStep1 = referenceStep;
                if (context.UseShadowProperties)
                {
                    shadowProperty = DesignTimeProperties.GetShadowProperty(propertyKey, viewNode.DocumentNode.Type);
                }
                else
                {
                    shadowProperty = null;
                }
                IPropertyId propertyId = shadowProperty;
                if (propertyId != null && DesignTimeProperties.UseShadowPropertyForInstanceBuilding(context.DocumentContext.TypeResolver, propertyId))
                {
                    referenceStep1 = propertyId as ReferenceStep;
                }
                if (referenceStep1 != null)
                {
                    IInstantiatedElementViewNode instantiatedElementViewNode = viewNode as IInstantiatedElementViewNode;
                    if (instantiatedElementViewNode == null)
                    {
                        referenceStep1.ClearValue(viewNode.Instance);
                    }
                    else
                    {
                        foreach (object instantiatedElement in instantiatedElementViewNode.InstantiatedElements)
                        {
                            referenceStep1.ClearValue(instantiatedElement);
                        }
                    }
                }
            }
            if (propertyKey.DeclaringType.Metadata.IsNameProperty(propertyKey) && InstanceBuilderOperations.GetIsInlinedResourceWithoutNamescope(viewNode))
            {
                InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, propertyKey, valueNode);
                return;
            }
            INameScope nameScope = context.NameScope;
            bool       flag      = (nameScope == null ? false : propertyKey.DeclaringType.Metadata.IsNameProperty(propertyKey));

            if (flag)
            {
                ViewNode item1 = viewNode.Properties[propertyKey];
                if (item1 != null)
                {
                    str = item1.Instance as string;
                }
                else
                {
                    str = null;
                }
                string str1 = str;
                if (!string.IsNullOrEmpty(str1) && nameScope.FindName(str1) != null)
                {
                    context.NameScope.UnregisterName(str1);
                }
            }
            if ((!context.IsSerializationScope || !(propertyKey is Event)) && (context.IsSerializationScope || !DesignTimeProperties.IsDocumentOnlyDesignTimeProperty(propertyKey)))
            {
                base.UpdateProperty(context, viewNode, propertyKey, valueNode);
            }
            else
            {
                InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, propertyKey, valueNode);
            }
            if (flag)
            {
                ViewNode viewNode1 = viewNode.Properties[propertyKey];
                if (viewNode1 != null)
                {
                    instance = viewNode1.Instance as string;
                }
                else
                {
                    instance = null;
                }
                string str2 = instance;
                if (!string.IsNullOrEmpty(str2))
                {
                    try
                    {
                        if (!str2.StartsWith("~", StringComparison.Ordinal) && !str2.Contains("."))
                        {
                            if (nameScope.FindName(str2) != null)
                            {
                                nameScope.UnregisterName(str2);
                            }
                            nameScope.RegisterName(str2, viewNode.Instance);
                        }
                    }
                    catch (ArgumentException argumentException1)
                    {
                        ArgumentException argumentException = argumentException1;
                        ViewNodeManager   viewNodeManager   = viewNode1.ViewNodeManager;
                        CultureInfo       currentCulture    = CultureInfo.CurrentCulture;
                        string            instanceBuilderUnableToRegisterName = ExceptionStringTable.InstanceBuilderUnableToRegisterName;
                        object[]          objArray = new object[] { str2 };
                        viewNodeManager.OnException(viewNode1, new InstanceBuilderException(string.Format(currentCulture, instanceBuilderUnableToRegisterName, objArray), argumentException, viewNode1.DocumentNode, viewNode), false);
                    }
                }
            }
        }
Exemplo n.º 8
0
        public static DocumentNode GetShadowPropertyNode(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode)
        {
            IType valueAsType;
            DocumentNodeMemberValue value;
            ReferenceStep           member;

            if (!context.UseShadowProperties || propertyKey == null || !KnownProperties.SetterPropertyProperty.Equals(propertyKey))
            {
                return(null);
            }
            if (context.ContainerRoot == null || !PlatformTypes.Style.IsAssignableFrom(context.ContainerRoot.Type))
            {
                return(null);
            }
            DocumentCompositeNode documentNode = (DocumentCompositeNode)context.ContainerRoot.DocumentNode;
            DocumentPrimitiveNode item         = documentNode.Properties[KnownProperties.StyleTargetTypeProperty] as DocumentPrimitiveNode;

            if (item != null)
            {
                valueAsType = DocumentPrimitiveNode.GetValueAsType(item);
            }
            else
            {
                valueAsType = null;
            }
            IType type = valueAsType;

            if (type == null)
            {
                return(null);
            }
            DocumentPrimitiveNode documentPrimitiveNode = valueNode as DocumentPrimitiveNode;

            if (documentPrimitiveNode != null)
            {
                value = documentPrimitiveNode.Value as DocumentNodeMemberValue;
            }
            else
            {
                value = null;
            }
            DocumentNodeMemberValue documentNodeMemberValue = value;

            if (documentNodeMemberValue != null)
            {
                member = documentNodeMemberValue.Member as ReferenceStep;
            }
            else
            {
                member = null;
            }
            ReferenceStep referenceStep = member;

            if (referenceStep == null)
            {
                return(null);
            }
            if (context.RootTargetTypeReplacement != null)
            {
                ViewNode viewNode1 = StyleControlTemplateHelper.FindStyleTemplateOwningViewNode(viewNode);
                if (viewNode1 == null || viewNode1 == viewNode.ViewNodeManager.Root)
                {
                    IProperty replacementProperty = context.RootTargetTypeReplacement.GetReplacementProperty(referenceStep);
                    if (replacementProperty != null && replacementProperty != referenceStep)
                    {
                        return(context.DocumentContext.CreateNode(valueNode.Type, new DocumentNodeMemberValue(replacementProperty)));
                    }
                }
            }
            IProperty shadowProperty = DesignTimeProperties.GetShadowProperty(referenceStep, type);

            if (shadowProperty == null)
            {
                return(null);
            }
            if (!DesignTimeProperties.UseShadowPropertyForInstanceBuilding(context.DocumentContext.TypeResolver, shadowProperty))
            {
                return(null);
            }
            DocumentPrimitiveNode documentPrimitiveNode1 = context.DocumentContext.CreateNode(valueNode.Type, new DocumentNodeMemberValue(shadowProperty));

            return(documentPrimitiveNode1);
        }