コード例 #1
0
        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);
        }
コード例 #2
0
 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);
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }