Esempio n. 1
0
 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);
 }
        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);
        }
        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 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);
            }
        }