protected bool DoesStyleOrTemplateApply(IPropertyId styleOrTemplateProperty, DocumentNode value) { if (PlatformTypes.FrameworkElement.IsAssignableFrom((ITypeId)this.Type)) { IType templateTargetType1 = DocumentNodeUtilities.GetStyleOrTemplateTargetType(value); Type type = templateTargetType1 != null ? templateTargetType1.RuntimeType : (Type)null; Type c = this.TargetElement.ProjectContext.MetadataFactory.GetMetadata(this.Type.RuntimeType).GetStylePropertyTargetType(styleOrTemplateProperty); if (type == (Type)null) { return(true); } if (StyleNode.BasedOnProperty.Equals((object)styleOrTemplateProperty)) { StyleNode styleNode = this.TargetElement as StyleNode; if (styleNode != null) { IType templateTargetType2 = DocumentNodeUtilities.GetStyleOrTemplateTargetType(styleNode.DocumentNode); c = templateTargetType2 != null ? templateTargetType2.RuntimeType : (Type)null; } } if (c == (Type)null && ControlStylingOperations.DoesPropertyAffectRoot((IPropertyId)this.TargetProperty)) { c = this.Type.RuntimeType; } if (c != (Type)null && !type.IsAssignableFrom(c)) { return(false); } } return(true); }
public static DocumentNodePath ResolveNodePathForTemplateWithinExistingStyle(SceneElement targetElement, PropertyReference targetPropertyReference) { DocumentNodePath documentNodePath = ControlStylingOperations.ProvideStyleOrTemplateNodePath(targetElement, targetPropertyReference); if (documentNodePath != null) { SceneView defaultView = targetElement.ViewModel.DefaultView; ICollection <IViewObject> instantiatedElements = defaultView.GetInstantiatedElements(documentNodePath); if (instantiatedElements.Count <= 0) { return(ControlStylingOperations.FindTemplateWithinStyle(documentNodePath, targetElement, ControlElement.TemplateProperty, (IPropertyId)targetPropertyReference[0])); } foreach (IViewObject viewObject in (IEnumerable <IViewObject>)instantiatedElements) { if (PlatformTypes.Control.IsAssignableFrom((ITypeId)viewObject.GetIType((ITypeResolver)targetElement.ProjectContext))) { object platformObject = viewObject.GetValue(targetElement.ProjectContext.ResolveProperty(ControlElement.TemplateProperty)); if (platformObject != null) { IViewObject instance = targetElement.ViewModel.ProjectContext.Platform.ViewObjectFactory.Instantiate(platformObject); DocumentNodePath correspondingNodePath = defaultView.GetCorrespondingNodePath(instance, true); if (correspondingNodePath != null && ControlStylingOperations.ShouldSetEditingContextToNodePath(correspondingNodePath, targetElement, targetPropertyReference[0])) { return(correspondingNodePath); } } } } } return((DocumentNodePath)null); }
protected override bool IsCommandProperty(ReferenceStep referenceStep) { if (base.IsCommandProperty(referenceStep) && EditTemplatesListCommand.IsCommandProperty(this.TargetElement, referenceStep)) { return(true); } if (EditStylesListCommand.IsCommandProperty(this.TargetElement, referenceStep)) { return(ControlStylingOperations.DoesStyleTargetControl(this.ViewModel.ProjectContext, this.TargetElement.Type, (IPropertyId)referenceStep)); } return(false); }
private static bool UpdateNavigationInfo(ControlStylingOperations.EditScope scope) { if (scope.NodePath == null) { PropertyReference targetPropertyReference = new PropertyReference(scope.TargetProperty); scope.NodePath = ControlStylingOperations.ProvideStyleOrTemplateNodePath(scope.TargetElement, targetPropertyReference); } if (scope.NodePath != null) { scope.Node = scope.NodePath.Node; scope.EditInPlace = ControlStylingOperations.CanEditInPlace(scope.TargetElement, scope.TargetProperty, scope.NodePath); } return(scope.NodePath != null); }
public static DocumentNodePath ProvideStyleOrTemplateNodePath(SceneElement targetElement, PropertyReference targetPropertyReference) { DocumentNodePath documentNodePath = (DocumentNodePath)null; ReferenceStep targetProperty = targetPropertyReference[0]; StyleNode styleNode = targetElement as StyleNode; if (targetPropertyReference.TargetType.IsAssignableFrom(targetElement.TargetType) || styleNode != null && targetPropertyReference.TargetType.IsAssignableFrom(styleNode.StyleTargetType)) { IViewObjectFactory viewObjectFactory = targetElement.Platform.ViewObjectFactory; object computedValue = targetElement.GetComputedValue(targetPropertyReference); DocumentNodePath valuePath = (DocumentNodePath)null; if (computedValue != null) { IViewObject instance = viewObjectFactory.Instantiate(computedValue); valuePath = targetElement.ViewModel.DefaultView.GetCorrespondingNodePath(instance, true); } if (valuePath == null && !BaseFrameworkElement.StyleProperty.Equals((object)targetProperty)) { BaseFrameworkElement frameworkElement = targetElement as BaseFrameworkElement; if (frameworkElement != null) { frameworkElement.FindMissingImplicitStyle(); } if (computedValue != null) { IViewObject instance = viewObjectFactory.Instantiate(computedValue); DocumentNodePath correspondingNodePath = targetElement.ViewModel.DefaultView.GetCorrespondingNodePath(instance, true); if (correspondingNodePath != null) { valuePath = ControlStylingOperations.FindTemplateWithinStyle(correspondingNodePath, targetElement, (IPropertyId)targetProperty, (IPropertyId)targetProperty); } } } if (ControlStylingOperations.ShouldSetEditingContextToNodePath(valuePath, targetElement, targetProperty)) { documentNodePath = valuePath; } } if (documentNodePath == null && styleNode != null && targetElement.IsSet(targetPropertyReference) == PropertyState.Set) { DocumentNodePath valueAsDocumentNode = targetElement.GetLocalValueAsDocumentNode(targetPropertyReference); if (ControlStylingOperations.ShouldSetEditingContextToNodePath(valueAsDocumentNode, targetElement, targetProperty)) { documentNodePath = valueAsDocumentNode; } } return(documentNodePath); }
protected override DocumentNode ProvideValue(out IList <DocumentCompositeNode> auxillaryResources) { auxillaryResources = (IList <DocumentCompositeNode>)null; FrameworkTemplateElement frameworkTemplateElement = (FrameworkTemplateElement)this.SceneViewModel.CreateSceneNode((ITypeId)this.TargetProperty.PropertyType); if (ControlStylingOperations.DoesPropertyAffectRoot((IPropertyId)this.TargetProperty)) { ControlTemplateElement controlTemplateElement = frameworkTemplateElement as ControlTemplateElement; if (controlTemplateElement != null) { controlTemplateElement.ControlTemplateTargetTypeId = (ITypeId)this.Type; } } BaseFrameworkElement frameworkElement = !PlatformTypes.ItemsPanelTemplate.Equals((object)frameworkTemplateElement.Type) ? (BaseFrameworkElement)this.SceneViewModel.CreateSceneNode(PlatformTypes.Grid) : (BaseFrameworkElement)this.SceneViewModel.CreateSceneNode(PlatformTypes.StackPanel); frameworkTemplateElement.DefaultInsertionPoint.Insert((SceneNode)frameworkElement); return(frameworkTemplateElement.DocumentNode); }
public override void Execute() { using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.UndoUnitEditStyleTemplate, new object[1] { (object)this.TargetPropertyReference.Path }), 1 != 0)) { this.SceneView.CandidateEditingContainer = this.TargetElement.DocumentNodePath; editTransaction.Update(); DocumentNodePath templateNodePath = this.StyleOrTemplateNodePath; this.SceneView.CandidateEditingContainer = (DocumentNodePath)null; if (templateNodePath != null) { bool preferInPlaceEdit = ControlStylingOperations.CanEditInPlace(this.TargetElement, this.TargetProperty, templateNodePath); ControlStylingOperations.SetActiveEditingContainer(this.TargetElement, this.TargetProperty, templateNodePath.Node, templateNodePath, preferInPlaceEdit, editTransaction); } editTransaction.Commit(); } }
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); }
public static SceneNode SetActiveEditingContainer(SceneElement targetElement, ReferenceStep targetProperty, DocumentNode node, DocumentNodePath knownPath, bool preferInPlaceEdit, SceneEditTransaction outerTransaction) { ControlStylingOperations.EditScope scope = new ControlStylingOperations.EditScope() { TargetElement = targetElement, TargetProperty = targetProperty, Node = node, NodePath = knownPath, EditInPlace = preferInPlaceEdit }; SceneNode sceneNode = (SceneNode)null; ControlStylingOperations.EditScope templateScope; ControlStylingOperations.EditScope styleScope; if (ControlStylingOperations.ShouldNavigateToIntermediateStyle(scope, out templateScope, out styleScope)) { templateScope.TargetElement = ControlStylingOperations.SetActiveEditingContainerInternal(styleScope) as SceneElement; if (templateScope.TargetElement != null) { templateScope.TargetElement.ViewModel.EditContextManager.ActiveEditContext.EnsureHidden(); if (outerTransaction != null) { outerTransaction.Update(); } if (ControlStylingOperations.UpdateNavigationInfo(templateScope)) { sceneNode = ControlStylingOperations.SetActiveEditingContainerInternal(templateScope); } } } if (sceneNode == null) { sceneNode = ControlStylingOperations.SetActiveEditingContainerInternal(scope); } return(sceneNode); }
private static SceneNode SetActiveEditingContainerInternal(ControlStylingOperations.EditScope scope) { SceneViewModel viewModel = scope.TargetElement.ViewModel.GetViewModel(scope.Node.DocumentRoot, true); if (viewModel == null) { return((SceneNode)null); } SceneElement selectionToSet = (SceneElement)viewModel.GetSceneNode(scope.Node); if (selectionToSet.IsLocked) { using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.UndoUnitEditStyleTemplate, new object[1] { (object)scope.TargetProperty.Name }))) { selectionToSet.IsLocked = false; editTransaction.Commit(); } } if (viewModel == scope.TargetElement.ViewModel && scope.EditInPlace) { if (scope.NodePath != null) { viewModel.ActiveEditingContainerPath = scope.NodePath; } } else { IPropertyId ancestorPropertyKey = (IPropertyId)scope.TargetProperty; if (scope.NodePath != null) { DocumentNodePath documentNodePath = scope.NodePath; ancestorPropertyKey = (IPropertyId)documentNodePath.ContainerOwnerProperty; while ((documentNodePath = documentNodePath.GetContainerOwnerPath()) != null && documentNodePath.Node != scope.TargetElement.DocumentNode) { ancestorPropertyKey = (IPropertyId)documentNodePath.ContainerOwnerProperty; } } BaseFrameworkElement frameworkElement = scope.TargetElement as BaseFrameworkElement; Size preferredSize = frameworkElement == null || !frameworkElement.IsViewObjectValid || !ControlStylingOperations.DoesPropertyAffectRoot((IPropertyId)scope.TargetProperty) ? Size.Empty : frameworkElement.GetComputedBounds((Base2DElement)frameworkElement).Size; viewModel.SetViewRoot(scope.TargetElement.ViewModel.DefaultView, scope.TargetElement, ancestorPropertyKey, scope.Node, preferredSize); viewModel.DefaultView.EnsureDesignSurfaceVisible(); } if (viewModel.IsEditable) { viewModel.ElementSelectionSet.SetSelection(selectionToSet); } return(viewModel.ActiveEditingContainer); }
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); }
public static bool ShouldSetEditingContextToNodePath(DocumentNodePath valuePath, SceneElement targetElement, ReferenceStep targetProperty) { if (valuePath != null) { DocumentNode node = valuePath.Node; if (node != null && (PlatformTypes.FrameworkTemplate.IsAssignableFrom((ITypeId)node.Type) || PlatformTypes.Style.IsAssignableFrom((ITypeId)node.Type) && node is DocumentCompositeNode && (!targetProperty.Equals((object)BaseFrameworkElement.StyleProperty) || !PlatformTypes.Style.IsAssignableFrom((ITypeId)targetElement.Type))) && !ControlStylingOperations.IsInsideDefaultStyleOrTemplate(valuePath)) { DocumentNodePath containerOwnerPath = valuePath.GetContainerOwnerPath(); if (!valuePath.IsValid()) { return(false); } if (containerOwnerPath != null) { return(!containerOwnerPath.Contains(valuePath.Node)); } return(true); } } return(false); }
protected override DocumentNodePath ProvideEditingContainer(SceneElement targetElement, PropertyReference targetProperty, DocumentNode resourceNode) { return(ControlStylingOperations.ResolveNodePathForTemplateWithinExistingStyle(targetElement, targetProperty) ?? base.ProvideEditingContainer(targetElement, targetProperty, resourceNode)); }
public override void Execute() { PerformanceUtility.StartPerformanceSequence(PerformanceEvent.EditStyleOrTemplate); if (this.IsEnabled) { SceneElement targetElement = this.TargetElement; IDocumentContext documentContext = this.SceneViewModel.Document.DocumentContext; Type propertyTargetType = this.SceneViewModel.Document.ProjectContext.MetadataFactory.GetMetadata(this.Type.RuntimeType).GetStylePropertyTargetType((IPropertyId)this.TargetProperty); CreateResourceModel.ContextFlags contextFlags = !PlatformTypes.ControlTemplate.IsAssignableFrom((ITypeId)this.TargetProperty.PropertyType) ? (this.SceneViewModel.ProjectContext.IsCapabilitySet(PlatformCapability.SupportsImplicitStyles) ? CreateResourceModel.ContextFlags.CanApplyAutomatically : CreateResourceModel.ContextFlags.None) : CreateResourceModel.ContextFlags.None; CreateResourceModel model = new CreateResourceModel(this.SceneViewModel, this.DesignerContext.ResourceManager, PlatformTypeHelper.GetPropertyType((IProperty)this.TargetProperty), propertyTargetType, this.TargetProperty.Name, (SceneElement)null, (SceneNode)(targetElement as BaseFrameworkElement), contextFlags); IList <DocumentCompositeNode> auxillaryResources; DocumentNode node1 = this.ProvideValue(out auxillaryResources); if (node1 != null) { IPropertyId targetTypeProperty = this.GetTargetTypeProperty((ITypeId)this.TargetProperty.PropertyType); DocumentCompositeNode documentCompositeNode = node1 as DocumentCompositeNode; if (targetTypeProperty != null && documentCompositeNode != null) { IType valueAsType = DocumentPrimitiveNode.GetValueAsType(documentCompositeNode.Properties[targetTypeProperty]); if (valueAsType != null && valueAsType.RuntimeType != (Type)null) { model.TargetType = valueAsType.RuntimeType; } } else { model.TargetType = (Type)null; } ReplaceStyleTemplateCommand.ExtraReferences references = new ReplaceStyleTemplateCommand.ExtraReferences(); this.CollectExtraReferences(node1, references); if (auxillaryResources != null) { foreach (DocumentNode node2 in (IEnumerable <DocumentCompositeNode>)auxillaryResources) { this.CollectExtraReferences(node2, references); } } if (references.UnresolvedTypes.Count > 0) { string message = string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.CopyStyleTemplateTypesNotInDocumentMessage, new object[2] { (object)this.TargetProperty.Name, (object)SceneView.GetUnresolvedTypesList(references.UnresolvedTypes) }); if (!this.ShowUI) { return; } this.DesignerContext.MessageDisplayService.ShowError(message); return; } if (this.ShowUI) { bool?nullable = new CreateResourceDialog(this.DesignerContext, model).ShowDialog(); if ((!nullable.GetValueOrDefault() ? 1 : (!nullable.HasValue ? true : false)) != 0) { return; } } bool flag = model.CurrentResourceSite != null; if (!flag || targetElement.DocumentNode.DocumentRoot == null) { return; } SceneViewModel viewModel = this.SceneViewModel.GetViewModel(model.CurrentResourceSite.HostNode.DocumentRoot, false); if (viewModel == null || !PlatformTypes.PlatformsCompatible(node1.PlatformMetadata, viewModel.ProjectContext.PlatformMetadata) || !this.AddReferences(viewModel.ProjectContext, references, model.KeyString)) { return; } using (SceneEditTransaction editTransaction1 = this.SceneViewModel.CreateEditTransaction(this.UndoString)) { DocumentNode documentNode1 = (DocumentNode)null; DocumentCompositeNode resource; using (SceneEditTransaction editTransaction2 = viewModel.CreateEditTransaction(this.UndoString)) { DocumentNode newResourceNode; try { newResourceNode = node1.Clone(viewModel.Document.DocumentContext); } catch { editTransaction2.Cancel(); editTransaction1.Cancel(); this.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.CommandFailedDialogMessage, new object[1] { (object)this.UndoString })); return; } newResourceNode.Name = (string)null; bool useStaticResource = !(this.TargetProperty is DependencyPropertyReferenceStep) || !JoltHelper.TypeSupported((ITypeResolver)this.SceneViewModel.ProjectContext, PlatformTypes.DynamicResource); int index = useStaticResource ? model.IndexInResourceSite(targetElement.DocumentNode) : -1; resource = model.CreateResource(newResourceNode, targetTypeProperty, index); flag = resource != null; if (flag) { documentNode1 = model.CreateResourceReference(this.SceneViewModel.Document.DocumentContext, resource, useStaticResource); flag = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CopyResourcesToNewResourceSite(auxillaryResources, viewModel, model.CurrentResourceSite.HostNode, resource, model.IndexInResourceSite((DocumentNode)resource)); } if (flag) { editTransaction2.Commit(); if (this.SceneViewModel == viewModel) { editTransaction1.Update(); this.DesignerContext.ViewUpdateManager.UpdateRelatedViews(this.SceneViewModel.Document, false); } this.DesignerContext.ViewUpdateManager.RefreshActiveViewApplicationResources(); } else { editTransaction2.Cancel(); } } if (flag && resource != null) { DocumentNode documentNode2 = resource.Properties[DictionaryEntryNode.ValueProperty]; DocumentNodePath documentNodePath; if (targetElement.IsAttached) { if (documentNode1 != null) { targetElement.SetValue(this.TargetPropertyReference, (object)documentNode1); } else { targetElement.ClearValue(this.TargetPropertyReference); } this.SceneView.CandidateEditingContainer = targetElement.DocumentNodePath; editTransaction1.Update(); this.SceneView.CandidateEditingContainer = (DocumentNodePath)null; documentNodePath = this.ProvideEditingContainer(targetElement, this.TargetPropertyReference, documentNode2); } else { documentNodePath = (DocumentNodePath)null; } if (this.SceneView.IsValid) { if (documentNodePath != null && documentNodePath.Node != null && (!DocumentNodeUtilities.IsDynamicResource(documentNodePath.Node) && !DocumentNodeUtilities.IsStaticResource(documentNodePath.Node))) { DocumentNode node2 = documentNodePath.Node; bool preferInPlaceEdit = ControlStylingOperations.CanEditInPlace(targetElement, this.TargetProperty, documentNodePath); ControlStylingOperations.SetActiveEditingContainer(targetElement, this.TargetProperty, node2, documentNodePath, preferInPlaceEdit, editTransaction1); } else { ControlStylingOperations.SetActiveEditingContainer(targetElement, this.TargetProperty, documentNode2, (DocumentNodePath)null, false, editTransaction1); } } editTransaction1.Commit(); } else { editTransaction1.Cancel(); } } } } PerformanceUtility.EndPerformanceSequence(PerformanceEvent.EditStyleOrTemplate); }
private static void ReplaceTemplateTargetType(DocumentNode root, IList <DocumentCompositeNode> resources, IType targetType) { DocumentCompositeNode node = root as DocumentCompositeNode; if (node == null) { return; } DocumentCompositeNode parent = root.Parent; if (parent != null && PlatformTypes.Setter.IsAssignableFrom((ITypeId)parent.Type) && (parent.TypeResolver.ResolveProperty(SetterSceneNode.TargetNameProperty) == null || parent.Properties[SetterSceneNode.TargetNameProperty] == null) && (ControlStylingOperations.DoesPropertyAffectRoot((IPropertyId)root.GetValueProperty()) && parent.Properties[SetterSceneNode.ValueProperty] == root)) { if (PlatformTypes.ControlTemplate.IsAssignableFrom((ITypeId)root.Type)) { node.Properties[ControlTemplateElement.TargetTypeProperty] = (DocumentNode)node.Context.CreateNode(PlatformTypes.Type, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)targetType)); } else if (DocumentNodeUtilities.IsDynamicResource(root) || DocumentNodeUtilities.IsStaticResource(root)) { DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(node); if (resourceKey != null && resources != null) { foreach (DocumentCompositeNode entryNode in (IEnumerable <DocumentCompositeNode>)resources) { if (resourceKey.Equals(ResourceNodeHelper.GetResourceEntryKey(entryNode))) { DocumentCompositeNode documentCompositeNode = entryNode.Properties[DictionaryEntryNode.ValueProperty] as DocumentCompositeNode; if (documentCompositeNode != null) { if (PlatformTypes.ControlTemplate.IsAssignableFrom((ITypeId)documentCompositeNode.Type)) { documentCompositeNode.Properties[ControlTemplateElement.TargetTypeProperty] = (DocumentNode)documentCompositeNode.Context.CreateNode(PlatformTypes.Type, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)targetType)); break; } break; } break; } } } } } if (parent != null && DocumentNodeUtilities.IsStyleOrTemplate(root.Type)) { return; } foreach (DocumentNode root1 in node.ChildNodes) { ReplaceStyleTemplateCommand.ReplaceTemplateTargetType(root1, resources, targetType); } }