Beispiel #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)
            {
            }
        }
        private static object CreateXmlDataContext(DataSourceInfo dataSource, SceneViewModel viewModel)
        {
            DocumentNode sourceNode = dataSource.SourceNode;
            object       obj        = (object)null;

            using (StandaloneInstanceBuilderContext instanceBuilderContext = new StandaloneInstanceBuilderContext(viewModel.Document.DocumentContext, viewModel.DesignerContext))
            {
                try
                {
                    IInstanceBuilder builder  = instanceBuilderContext.InstanceBuilderFactory.GetBuilder(sourceNode.TargetType);
                    ViewNode         viewNode = builder.GetViewNode((IInstanceBuilderContext)instanceBuilderContext, sourceNode);
                    obj = (object)(bool)(builder.Instantiate((IInstanceBuilderContext)instanceBuilderContext, viewNode) ? true : false);
                }
                catch
                {
                }
            }
            ReferenceStep referenceStep  = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(XmlDataProviderSceneNode.XPathProperty);
            string        inheritedXPath = referenceStep.GetValue(obj) as string;

            if (string.IsNullOrEmpty(inheritedXPath))
            {
                inheritedXPath = dataSource.Path;
            }
            else if (!string.IsNullOrEmpty(dataSource.Path))
            {
                inheritedXPath = XmlSchema.CombineXPaths(inheritedXPath, dataSource.Path);
            }
            if (!string.IsNullOrEmpty(inheritedXPath))
            {
                referenceStep.SetValue(obj, (object)inheritedXPath);
            }
            return(obj);
        }
        protected override DocumentNode CreateValue(BaseFrameworkElement source)
        {
            object tileBrush = this.CreateTileBrush(source);

            if (tileBrush == null)
            {
                return((DocumentNode)null);
            }
            ITypeResolver typeResolver = (ITypeResolver)source.ProjectContext;
            IViewObject   visual       = source.Visual;

            if (visual != null)
            {
                object platformSpecificObject = visual.PlatformSpecificObject;
                if (platformSpecificObject != null && PlatformTypes.Image.IsAssignableFrom((ITypeId)visual.GetIType((ITypeResolver)this.SceneViewModel.ProjectContext)))
                {
                    ReferenceStep referenceStep = typeResolver.ResolveProperty(TileBrushNode.StretchProperty) as ReferenceStep;
                    object        obj           = referenceStep.GetValue(tileBrush);
                    object        valueToSet    = (typeResolver.ResolveProperty(ImageElement.StretchProperty) as ReferenceStep).GetValue(platformSpecificObject);
                    if (!obj.Equals(valueToSet))
                    {
                        referenceStep.SetValue(tileBrush, valueToSet);
                    }
                }
            }
            return(this.SceneViewModel.Document.DocumentContext.CreateNode(typeResolver.ResolveType(PlatformTypes.TileBrush).RuntimeType, tileBrush));
        }
Beispiel #4
0
        private object ConvertImageBrush(object value, object result, ITypeResolver sourceTypeResolver, ITypeResolver targetTypeResolver)
        {
            ReferenceStep referenceStep1 = (ReferenceStep)sourceTypeResolver.ResolveProperty(TileBrushNode.StretchProperty);
            ReferenceStep referenceStep2 = (ReferenceStep)targetTypeResolver.ResolveProperty(TileBrushNode.StretchProperty);
            object        valueToSet1    = this.ConvertInternalFast(referenceStep1.GetValue(value), sourceTypeResolver, targetTypeResolver);

            referenceStep2.SetValue(result, valueToSet1);
            object objToInspect = ((ReferenceStep)sourceTypeResolver.ResolveProperty(ImageBrushNode.ImageSourceProperty)).GetValue(value);

            if (!PlatformTypes.IsInstance(objToInspect, PlatformTypes.BitmapImage, sourceTypeResolver))
            {
                return(result);
            }
            object obj1 = ((ReferenceStep)sourceTypeResolver.ResolveProperty(BitmapImageNode.UriSourceProperty)).GetValue(objToInspect);

            if (obj1 == null)
            {
                return(result);
            }
            Type   type1 = obj1.GetType();
            IType  type2 = targetTypeResolver.ResolveType(PlatformTypes.Uri);
            string text  = Microsoft.Expression.DesignModel.Metadata.MetadataStore.GetTypeConverter(type1).ConvertToInvariantString(obj1);

            if (string.IsNullOrEmpty(text))
            {
                return(result);
            }
            object        valueToSet2    = Microsoft.Expression.DesignModel.Metadata.MetadataStore.GetTypeConverter(type2.RuntimeType).ConvertFromInvariantString(text);
            ReferenceStep referenceStep3 = (ReferenceStep)targetTypeResolver.ResolveProperty(ImageBrushNode.ImageSourceProperty);
            object        obj2           = InstanceBuilderOperations.InstantiateType(targetTypeResolver.ResolveType(PlatformTypes.BitmapImage).RuntimeType, true);

            referenceStep3.SetValue(result, obj2);
            try
            {
                BitmapImage bitmapImage = obj2 as BitmapImage;
                if (bitmapImage != null)
                {
                    bitmapImage.BeginInit();
                    bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                }
                ((ReferenceStep)targetTypeResolver.ResolveProperty(BitmapImageNode.UriSourceProperty)).SetValue(obj2, valueToSet2);
                if (bitmapImage != null)
                {
                    bitmapImage.EndInit();
                }
            }
            catch (Exception ex)
            {
                result = (object)null;
            }
            return(result);
        }
Beispiel #5
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);
 }
Beispiel #6
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
            {
            }
        }
        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;
            }
        }
Beispiel #8
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);
        }
Beispiel #9
0
        private object ConvertInternalFast(object value, ITypeResolver sourceTypeResolver, ITypeResolver targetTypeResolver)
        {
            if (value == null)
            {
                return(value);
            }
            Type   type         = value.GetType();
            IType  platformType = ((IPlatformTypes)targetTypeResolver.PlatformMetadata).GetPlatformType(type.FullName);
            Type   runtimeType  = platformType.RuntimeType;
            object obj1;

            if (type.IsPrimitive || type.IsEnum)
            {
                if (runtimeType == (Type)null)
                {
                    return((object)null);
                }
                if (runtimeType.Equals(type))
                {
                    obj1 = value;
                }
                else
                {
                    TypeConverter typeConverter = Microsoft.Expression.DesignModel.Metadata.MetadataStore.GetTypeConverter(type);
                    obj1 = Microsoft.Expression.DesignModel.Metadata.MetadataStore.GetTypeConverter(runtimeType).ConvertFromInvariantString(typeConverter.ConvertToInvariantString(value));
                }
            }
            else
            {
                if (runtimeType == (Type)null)
                {
                    return((object)null);
                }
                obj1 = InstanceBuilderOperations.InstantiateType(runtimeType, true);
                if (obj1 != null && PlatformTypes.ImageBrush.IsAssignableFrom((ITypeId)platformType))
                {
                    return(this.ConvertImageBrush(value, obj1, sourceTypeResolver, targetTypeResolver));
                }
                if (!type.IsValueType)
                {
                    CollectionAdapterDescription adapterDescription = CollectionAdapterDescription.GetAdapterDescription(type);
                    if (adapterDescription != null)
                    {
                        IList list = CollectionAdapterDescription.GetAdapterDescription(runtimeType).GetCollectionAdapter(obj1) as IList;
                        foreach (object obj2 in (IEnumerable)adapterDescription.GetCollectionAdapter(value))
                        {
                            object obj3 = this.ConvertInternalFast(obj2, sourceTypeResolver, targetTypeResolver);
                            list.Add(obj3);
                        }
                    }
                }
                foreach (IProperty property in ((IPlatformTypes)sourceTypeResolver.PlatformMetadata).GetType(type).GetProperties(MemberAccessTypes.Public))
                {
                    ReferenceStep referenceStep1 = property as ReferenceStep;
                    if (referenceStep1 != null && referenceStep1.ReadAccess == MemberAccessType.Public && referenceStep1.WriteAccess == MemberAccessType.Public)
                    {
                        ReferenceStep referenceStep2 = platformType.GetMember(MemberType.Property, referenceStep1.Name, MemberAccessTypes.Public) as ReferenceStep;
                        if (referenceStep2 != null && referenceStep2.ReadAccess == MemberAccessType.Public && referenceStep2.WriteAccess == MemberAccessType.Public)
                        {
                            object valueToSet = this.ConvertInternalFast(referenceStep1.GetValue(value), sourceTypeResolver, targetTypeResolver);
                            referenceStep2.SetValue(obj1, valueToSet);
                        }
                    }
                }
            }
            return(obj1);
        }