Exemple #1
0
        public BaseFrameworkElement GetRelativeTargetElement(DocumentNodePath relativeEditingContainerPath)
        {
            if (relativeEditingContainerPath.ContainerNode != this.DocumentNode)
            {
                return((BaseFrameworkElement)null);
            }
            DocumentNodePath containerOwnerPath = relativeEditingContainerPath.GetContainerOwnerPath();

            if (containerOwnerPath == null)
            {
                return((BaseFrameworkElement)null);
            }
            SetterSceneNode setterSceneNode = this.ViewModel.GetSceneNode(containerOwnerPath.Node) as SetterSceneNode;

            if (setterSceneNode == null)
            {
                return(this.ViewModel.GetSceneNode(containerOwnerPath.Node) as BaseFrameworkElement);
            }
            IStoryboardContainer storyboardContainer = (IStoryboardContainer)this.ViewModel.GetSceneNode(containerOwnerPath.ContainerNode);
            SceneNode            sceneNode           = storyboardContainer.ResolveTargetName(setterSceneNode.Target);

            if (sceneNode == storyboardContainer)
            {
                return(storyboardContainer.TargetElement);
            }
            return(sceneNode as BaseFrameworkElement);
        }
        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);
        }
        public static bool IsInsideDefaultStyleOrTemplate(DocumentNodePath styleOrTemplate)
        {
            DocumentNodePath documentNodePath = styleOrTemplate;

            while (documentNodePath != null)
            {
                if (StyleNode.IsDefaultValue(documentNodePath.Node))
                {
                    return(true);
                }
                documentNodePath = documentNodePath.GetContainerOwnerPath();
                if (documentNodePath != null)
                {
                    documentNodePath = documentNodePath.GetContainerNodePath();
                }
            }
            return(false);
        }
Exemple #4
0
        public BaseFrameworkElement GetRelativeTargetElement(DocumentNodePath relativeEditingContainerPath)
        {
            if (relativeEditingContainerPath.ContainerNode != this.DocumentNode)
            {
                return((BaseFrameworkElement)null);
            }
            DocumentNodePath containerOwnerPath = relativeEditingContainerPath.GetContainerOwnerPath();

            if (containerOwnerPath == null)
            {
                return((BaseFrameworkElement)null);
            }
            SetterSceneNode setterSceneNode = this.ViewModel.GetSceneNode(containerOwnerPath.Node) as SetterSceneNode;

            if (setterSceneNode != null)
            {
                return(((ITriggerContainer)this.ViewModel.GetSceneNode(containerOwnerPath.ContainerNode)).ResolveTargetName(setterSceneNode.Target) as BaseFrameworkElement);
            }
            return(this.ViewModel.GetSceneNode(containerOwnerPath.Node) as BaseFrameworkElement);
        }
 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);
 }
        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);
        }