public static DocumentCompositeNode GetStyleSetter(DocumentCompositeNode styleNode, IPropertyId property) { DocumentCompositeNode documentCompositeNode; if (styleNode != null && property != null) { IPlatformMetadata platformMetadata = styleNode.Context.TypeResolver.PlatformMetadata; IProperty property1 = styleNode.Context.TypeResolver.ResolveProperty(property); DocumentCompositeNode item = styleNode.Properties[platformMetadata.KnownProperties.StyleSetters] as DocumentCompositeNode; if (item != null && item.SupportsChildren && property1 != null) { using (IEnumerator <DocumentNode> enumerator = item.Children.GetEnumerator()) { while (enumerator.MoveNext()) { DocumentCompositeNode current = enumerator.Current as DocumentCompositeNode; if (current == null) { continue; } IMemberId valueAsMember = DocumentNodeHelper.GetValueAsMember(current, KnownProperties.SetterPropertyProperty); if (valueAsMember == null || !property1.Equals(valueAsMember)) { continue; } documentCompositeNode = current; return(documentCompositeNode); } return(null); } return(documentCompositeNode); } } return(null); }
public override bool Instantiate(IInstanceBuilderContext context, ViewNode viewNode) { TemplateBindingInstanceBuilderBase.CheckForInvalidBinding(viewNode); bool flag = base.Instantiate(context, viewNode); if (context.RootTargetTypeReplacement != null && context.IsSerializationScope) { ViewNode viewNode1 = StyleControlTemplateHelper.FindContainingControlTemplate(viewNode); if (viewNode1 != null) { ViewNode viewNode2 = StyleControlTemplateHelper.FindStyleTemplateOwningViewNode(viewNode1); if (viewNode2 == null || viewNode2 == context.ViewNodeManager.Root) { DocumentCompositeNode documentNode = viewNode.DocumentNode as DocumentCompositeNode; if (documentNode != null && DocumentNodeUtilities.IsTemplateBinding(documentNode)) { IMemberId valueAsMember = DocumentNodeHelper.GetValueAsMember(documentNode, KnownProperties.TemplateBindingPropertyProperty); if (valueAsMember != null) { IProperty replacementProperty = context.RootTargetTypeReplacement.GetReplacementProperty(valueAsMember as IProperty); if (replacementProperty != null && replacementProperty is DependencyPropertyReferenceStep && replacementProperty != valueAsMember) { DocumentCompositeNode instance = (DocumentCompositeNode)viewNode.Instance; instance.Properties[KnownProperties.TemplateBindingPropertyProperty] = context.DocumentContext.CreateNode(PlatformTypes.DependencyProperty, new DocumentNodeMemberValue(replacementProperty)); } } } } } } return(flag); }
public static bool UseDesignTimeSize(object target, IInstanceBuilderContext context) { bool documentNode = false; if (context != null && context.ContainerRoot != null && context.ContainerRoot.DocumentNode != null && context.ContainerRoot.DocumentNode.DocumentRoot != null && context.ViewNodeManager != null && context.ViewNodeManager.Root != null) { ViewNode viewNode = context.InstanceDictionary.GetViewNode(target, true); if ((viewNode == null ? true : viewNode.Parent != null)) { documentNode = context.ViewNodeManager.Root.DocumentNode != context.ContainerRoot.DocumentNode.DocumentRoot.RootNode; IInstantiatedElementViewNode root = context.ViewNodeManager.Root as IInstantiatedElementViewNode; if (documentNode && root != null) { object first = root.InstantiatedElements.First; if (first != null && (bool)(context.DocumentContext.TypeResolver.ResolveProperty(DesignTimeProperties.IsEnhancedOutOfPlaceRootProperty) as DependencyPropertyReferenceStep).GetValue(first)) { documentNode = false; } } if (documentNode && viewNode != null) { DocumentNodePath containerNodePath = context.ViewNodeManager.GetCorrespondingNodePath(viewNode).GetContainerNodePath(); if (PlatformTypes.ControlTemplate.Equals(containerNodePath.Node.Type) && containerNodePath.Node != context.ViewNodeManager.Root.DocumentNode) { DocumentNodePath parent = containerNodePath.GetParent(); if (parent.Node.Type.Equals(PlatformTypes.Setter) && parent.Node is DocumentCompositeNode) { IMemberId valueAsMember = DocumentNodeHelper.GetValueAsMember((DocumentCompositeNode)parent.Node, Microsoft.Expression.DesignModel.Metadata.KnownProperties.SetterPropertyProperty); if (valueAsMember.Equals(Microsoft.Expression.DesignModel.Metadata.KnownProperties.ControlTemplateProperty) || valueAsMember.Equals(Microsoft.Expression.DesignModel.Metadata.KnownProperties.PageTemplateProperty)) { containerNodePath = parent.GetContainerNodePath(); } } } if (containerNodePath.Node != context.ViewNodeManager.Root.DocumentNode) { documentNode = false; } } } else { documentNode = true; } } return(documentNode); }
private static DocumentNodePath FindTemplateWithinStyle(DocumentNodePath styleNodePath, SceneElement targetElement, IPropertyId targetSetterProperty, IPropertyId targetProperty) { DocumentCompositeNode documentCompositeNode1 = styleNodePath.Node as DocumentCompositeNode; if (documentCompositeNode1 != null && PlatformTypes.Style.IsAssignableFrom((ITypeId)documentCompositeNode1.Type)) { DocumentCompositeNode documentCompositeNode2 = documentCompositeNode1.Properties[StyleNode.SettersProperty] as DocumentCompositeNode; if (documentCompositeNode2 != null && PlatformTypes.SetterBaseCollection.IsAssignableFrom((ITypeId)documentCompositeNode2.Type) && documentCompositeNode2.SupportsChildren) { foreach (DocumentNode documentNode in (IEnumerable <DocumentNode>)documentCompositeNode2.Children) { DocumentCompositeNode valueNode = documentNode as DocumentCompositeNode; if (valueNode != null && PlatformTypes.Setter.IsAssignableFrom((ITypeId)valueNode.Type)) { IProperty property = DocumentNodeHelper.GetValueAsMember(valueNode, SetterSceneNode.PropertyProperty) as IProperty; if (targetSetterProperty.Equals((object)property)) { DocumentNode expression = valueNode.Properties[SetterSceneNode.ValueProperty]; if (expression != null) { DocumentNodePath pathInContainer = styleNodePath.GetPathInContainer((DocumentNode)valueNode); DocumentNode newContainer = new ExpressionEvaluator(targetElement.ViewModel.DocumentRootResolver).EvaluateExpression(pathInContainer, expression); if (newContainer != null && newContainer.Parent != null) { DocumentNodePath pathInSubContainer = pathInContainer.GetPathInSubContainer(newContainer.SitePropertyKey, newContainer); if (ControlStylingOperations.ShouldSetEditingContextToNodePath(pathInSubContainer, targetElement, (ReferenceStep)documentCompositeNode1.TypeResolver.ResolveProperty(targetProperty))) { return(pathInSubContainer); } } } } } } } } return((DocumentNodePath)null); }
private static bool ShouldNavigateToIntermediateStyle(ControlStylingOperations.EditScope scope, out ControlStylingOperations.EditScope templateScope, out ControlStylingOperations.EditScope styleScope) { styleScope = (ControlStylingOperations.EditScope)null; templateScope = (ControlStylingOperations.EditScope)null; if (scope.EditInPlace || scope.Node == null || (scope.NodePath == null || PlatformTypes.Style.IsAssignableFrom((ITypeId)scope.TargetElement.Type)) || !PlatformTypes.FrameworkTemplate.IsAssignableFrom((ITypeId)scope.Node.Type)) { return(false); } DocumentCompositeNode valueNode = scope.NodePath.ContainerOwner as DocumentCompositeNode; if (valueNode == null || !PlatformTypes.Setter.IsAssignableFrom((ITypeId)valueNode.Type) || (valueNode.SitePropertyKey != null || valueNode.SiteChildIndex < 0)) { return(false); } DocumentCompositeNode parent1 = valueNode.Parent; if (parent1 == null || !PlatformTypes.SetterBaseCollection.IsAssignableFrom((ITypeId)parent1.Type) || (parent1.SitePropertyKey == null || !StyleNode.SettersProperty.Equals((object)parent1.SitePropertyKey))) { return(false); } DocumentCompositeNode parent2 = parent1.Parent; if (parent2 == null || !PlatformTypes.Style.IsAssignableFrom((ITypeId)parent2.Type)) { return(false); } ReferenceStep referenceStep1 = DocumentNodeHelper.GetValueAsMember(valueNode, SetterSceneNode.PropertyProperty) as ReferenceStep; if (referenceStep1 == null || !PlatformTypes.FrameworkTemplate.IsAssignableFrom((ITypeId)referenceStep1.PropertyType)) { return(false); } DocumentNodePath containerOwnerPath = scope.NodePath.GetContainerOwnerPath(); if (containerOwnerPath == null || containerOwnerPath.ContainerOwner == null) { return(false); } ReferenceStep referenceStep2 = (ReferenceStep)null; for (; containerOwnerPath != null; containerOwnerPath = containerOwnerPath.GetContainerOwnerPath()) { if (PlatformTypes.DictionaryEntry.IsAssignableFrom((ITypeId)containerOwnerPath.ContainerOwner.Type)) { referenceStep2 = containerOwnerPath.Node.TypeResolver.ResolveProperty(BaseFrameworkElement.StyleProperty) as ReferenceStep; break; } referenceStep2 = !PlatformTypes.Setter.IsAssignableFrom((ITypeId)containerOwnerPath.ContainerOwner.Type) ? containerOwnerPath.ContainerOwnerProperty as ReferenceStep : DocumentNodeHelper.GetValueAsMember((DocumentCompositeNode)containerOwnerPath.ContainerOwner, SetterSceneNode.PropertyProperty) as ReferenceStep; if (StyleNode.BasedOnProperty.Equals((object)referenceStep2)) { referenceStep2 = (ReferenceStep)null; } else { break; } } if (referenceStep2 == null || !PlatformTypes.Style.IsAssignableFrom((ITypeId)referenceStep2.PropertyType)) { return(false); } styleScope = new ControlStylingOperations.EditScope() { TargetElement = scope.TargetElement, TargetProperty = referenceStep2 }; if (!ControlStylingOperations.UpdateNavigationInfo(styleScope)) { return(false); } templateScope = new ControlStylingOperations.EditScope() { TargetProperty = referenceStep1 }; return(true); }