public static bool IsDefaultValue(DocumentNode node) { DocumentCompositeNode documentCompositeNode = node as DocumentCompositeNode; if (documentCompositeNode != null) { return(documentCompositeNode.GetValue <bool>(DesignTimeProperties.IsDefaultStyleProperty)); } return(StyleNode.IsReferenceValue(node)); }
internal static ResourceDictionaryUsage GetResourceDictionaryUsage(ResourceDictionaryContentProvider contentProvider) { ResourceDictionaryUsage resourceDictionaryUsage = ResourceDictionaryUsage.Unknown; if (contentProvider != null && contentProvider.Document != null && contentProvider.Document.RootNode != null) { DocumentCompositeNode documentCompositeNode = contentProvider.Document.RootNode as DocumentCompositeNode; if (documentCompositeNode != null) { if (documentCompositeNode.GetValue <bool>(DesignTimeProperties.IsSketchFlowStyleProperty)) { resourceDictionaryUsage |= ResourceDictionaryUsage.PrototypingStyles; } if (documentCompositeNode.GetValue <bool>(DesignTimeProperties.IsSketchFlowDefaultStyleProperty)) { resourceDictionaryUsage |= ResourceDictionaryUsage.PrototypingDefaultStyles; } } } return(resourceDictionaryUsage); }
private void Refresh() { List <DocumentNode> list = new List <DocumentNode>(this.contentProvider.Items); list.RemoveAll((Predicate <DocumentNode>)(target => { DocumentCompositeNode documentCompositeNode1 = target as DocumentCompositeNode; if (documentCompositeNode1 == null || !PlatformTypes.DictionaryEntry.Equals((object)documentCompositeNode1.Type)) { return(false); } DocumentNode documentNode = documentCompositeNode1.Properties[DictionaryEntryNode.ValueProperty]; DocumentCompositeNode documentCompositeNode2 = documentNode as DocumentCompositeNode; if (documentNode == null || PlatformTypes.Storyboard.IsAssignableFrom((ITypeId)documentNode.Type)) { return(true); } if (documentCompositeNode2 != null) { return(documentCompositeNode2.GetValue <bool>(DesignTimeProperties.IsDataSourceProperty)); } return(false); })); bool flag = this.ResourceItems.Count == list.Count; for (int index = 0; flag && index < list.Count; ++index) { flag = flag && this.ResourceItems[index].DocumentNode == list[index]; } if (!flag) { foreach (ResourceItem oldItem in (Collection <ResourceItem>) this.ResourceItems) { this.ResourceManager.OnItemRemoved(oldItem); } this.ResourceItems.Clear(); foreach (DocumentNode documentNode in list) { DocumentCompositeNode node = documentNode as DocumentCompositeNode; if (node != null) { this.ResourceItems.Add(this.ResourceManager.GetResourceItem((ResourceContainer)this, node)); } } } this.OnPropertyChanged("DocumentHasErrors"); }
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); }
public override bool AllowPostponedResourceUpdate(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNodePath evaluatedResource) { if (viewNode.Type.Metadata.NameProperty == propertyKey) { return(false); } DocumentNodePath editingContainer = context.ViewNodeManager.EditingContainer; if (editingContainer != null && DependencyObjectInstanceBuilderBase <T> .IsEvaluatedResourceWithinNodePath(editingContainer, viewNode, propertyKey, evaluatedResource)) { return(false); } if (context.IsSerializationScope && !PlatformTypes.UIElement.IsAssignableFrom(viewNode.Type)) { return(false); } if (evaluatedResource.Node != null && PlatformTypes.Visual.IsAssignableFrom(evaluatedResource.Node.Type)) { return(false); } DocumentCompositeNode node = evaluatedResource.Node as DocumentCompositeNode; if (node != null && node.PlatformMetadata.IsCapabilitySet(PlatformCapability.SupportNonSharedResources) && node.Properties[DesignTimeProperties.SharedProperty] != null && !node.GetValue <bool>(DesignTimeProperties.SharedProperty)) { return(false); } return(true); }
internal void ApplyAfterInsertionDefaultsToElements(IList <SceneNode> nodes, SceneNode rootNode) { foreach (SceneNode node in (IEnumerable <SceneNode>)nodes) { SceneElement element = node as SceneElement; if (element != null) { string name = element.Name; if (name == null) { StyleAsset relatedUserThemeAsset = this.GetRelatedUserThemeAsset(node, rootNode); if (relatedUserThemeAsset != null) { DocumentCompositeNode documentCompositeNode = relatedUserThemeAsset.ResourceModel.ValueNode as DocumentCompositeNode; if (documentCompositeNode != null) { name = documentCompositeNode.GetValue <string>(DesignTimeProperties.StyleDefaultContentProperty); double num1 = documentCompositeNode.GetValue <double>(DesignTimeProperties.ExplicitWidthProperty); if (num1 > 0.0) { DefaultTypeInstantiator.SetIfUnset(node, BaseFrameworkElement.WidthProperty, (object)num1); } double num2 = documentCompositeNode.GetValue <double>(DesignTimeProperties.ExplicitHeightProperty); if (num2 > 0.0) { DefaultTypeInstantiator.SetIfUnset(node, BaseFrameworkElement.HeightProperty, (object)num2); } } } } if (name == null) { name = element.TargetType.Name; } if (element.Name == null && this.ViewModel.DesignerContext.ProjectManager.OptionsModel.NameInteractiveElementsByDefault && Enumerable.FirstOrDefault <ITypeId>((IEnumerable <ITypeId>)DefaultTypeInstantiator.InteractiveElementTypes, (Func <ITypeId, bool>)(i => { IType type = this.ViewModel.ProjectContext.ResolveType(i); if (type != null) { return(type.IsAssignableFrom((ITypeId)element.Type)); } return(false); })) != null) { element.EnsureNamed(); } if (ProjectNeutralTypes.HeaderedContentControl.IsAssignableFrom((ITypeId)node.Type)) { DefaultTypeInstantiator.SetIfUnset(node, HeaderedControlProperties.HeaderedContentHeaderProperty, (object)name); } else if (ProjectNeutralTypes.HeaderedItemsControl.IsAssignableFrom((ITypeId)node.Type) && !PlatformTypes.ToolBar.IsAssignableFrom((ITypeId)node.Type)) { DefaultTypeInstantiator.SetIfUnset(node, HeaderedControlProperties.HeaderedItemsHeaderProperty, (object)name); } else if (PlatformTypes.ContentControl.IsAssignableFrom((ITypeId)node.Type) && !PlatformTypes.ScrollViewer.IsAssignableFrom((ITypeId)node.Type) && !PlatformTypes.UserControl.IsAssignableFrom((ITypeId)node.Type)) { if (ProjectNeutralTypes.TabItem.IsAssignableFrom((ITypeId)node.Type) && this.ViewModel.ProjectContext.IsCapabilitySet(PlatformCapability.UseHeaderOnTabItem)) { IPropertyId property = (IPropertyId)ProjectNeutralTypes.TabItem.GetMember(MemberType.LocalProperty, "Header", MemberAccessTypes.Public); DefaultTypeInstantiator.SetIfUnset(node, property, (object)name); } else { DefaultTypeInstantiator.SetIfUnset(node, ContentControlElement.ContentProperty, (object)name); } } else { BaseTextElement baseTextElement; if ((baseTextElement = node as BaseTextElement) != null) { if (string.IsNullOrEmpty(baseTextElement.Text.Trim())) { baseTextElement.Text = name; } if (PlatformTypes.TextBox.IsAssignableFrom((ITypeId)node.Type)) { DefaultTypeInstantiator.SetAsWpfIfUnset(node, TextBoxElement.TextWrappingProperty, (object)TextWrapping.Wrap); } if (!node.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf) && PlatformTypes.RichTextBox.IsAssignableFrom((ITypeId)node.Type)) { DefaultTypeInstantiator.SetAsWpfIfUnset(node, RichTextBoxElement.TextWrappingProperty, (object)TextWrapping.Wrap); } } else if (PlatformTypes.TextBlock.IsAssignableFrom((ITypeId)node.Type)) { DefaultTypeInstantiator.SetIfUnset(node, TextBlockElement.TextProperty, (object)name); DefaultTypeInstantiator.SetAsWpfIfUnset(node, TextBlockElement.TextWrappingProperty, (object)TextWrapping.Wrap); } else if (PlatformTypes.ListView.IsAssignableFrom((ITypeId)node.Type)) { GridViewElement gridViewElement = (GridViewElement)node.ViewModel.CreateSceneNode(PlatformTypes.GridView); SceneNode sceneNode = node.ViewModel.CreateSceneNode(PlatformTypes.GridViewColumn); gridViewElement.Columns.Add(sceneNode); node.SetValueAsSceneNode(DefaultTypeInstantiator.ListViewViewProperty, (SceneNode)gridViewElement); } else if (PlatformTypes.Border.IsAssignableFrom((ITypeId)node.Type)) { DefaultTypeInstantiator.SetAsWpfIfUnset(node, BorderElement.BorderBrushProperty, (object)Brushes.Black); DefaultTypeInstantiator.SetAsWpfIfUnset(node, BorderElement.BorderThicknessProperty, (object)new Thickness(1.0)); } else if (typeof(FlowDocumentScrollViewer).IsAssignableFrom(node.TargetType)) { DefaultTypeInstantiator.SetIfUnset(node, FlowDocumentScrollViewerElement.DocumentProperty, (object)new FlowDocument((Block) new Paragraph((Inline) new Run(name)))); } else if (typeof(Glyphs).IsAssignableFrom(node.TargetType)) { DefaultTypeInstantiator.SetIfUnset(node, DefaultTypeInstantiator.GlyphsUnicodeStringProperty, (object)name); DefaultTypeInstantiator.SetIfUnset(node, DefaultTypeInstantiator.GlyphsFillProperty, (object)Brushes.Black); DefaultTypeInstantiator.SetIfUnset(node, DefaultTypeInstantiator.GlyphsFontRenderingSizeEmProperty, (object)12.0); } else if (typeof(Viewport3D).IsAssignableFrom(node.TargetType)) { Viewport3DElement viewport3Delement = node as Viewport3DElement; if (viewport3Delement != null) { Camera camera1 = (Camera)Viewport3D.CameraProperty.DefaultMetadata.DefaultValue; Camera camera2 = (Camera)viewport3Delement.GetComputedValue(Viewport3DElement.CameraProperty); if (camera2 == null || PropertyUtilities.Compare((object)camera1, (object)camera2, this.sceneView)) { Camera perspectiveCamera = Helper3D.CreateEnclosingPerspectiveCamera(45.0, 1.0, new Rect3D(-1.0, -1.0, -1.0, 2.0, 2.0, 2.0), 1.0); DefaultTypeInstantiator.SetIfUnset((SceneNode)viewport3Delement, Viewport3DElement.CameraProperty, (object)perspectiveCamera); } } } } } } }