Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        private void ActivateTemplateEditingMode(SceneElement targetElement)
        {
            object computedValue = targetElement.GetComputedValue(ControlElement.TemplateProperty);

            if (computedValue == null)
            {
                return;
            }
            DocumentNodePath correspondingNodePath = this.SceneView.GetCorrespondingNodePath(this.SceneViewModel.ProjectContext.Platform.ViewObjectFactory.Instantiate(computedValue), true);

            if (correspondingNodePath == null)
            {
                return;
            }
            SceneViewModel viewModel = this.SceneViewModel.GetViewModel(correspondingNodePath.Node.DocumentRoot, true);

            if (this.SceneViewModel == viewModel)
            {
                viewModel.ActiveEditingContainerPath = correspondingNodePath;
            }
            else
            {
                IPropertyId          ancestorPropertyKey = (IPropertyId)(this.SceneViewModel.ProjectContext.ResolveProperty(BaseFrameworkElement.StyleProperty) as ReferenceStep);
                BaseFrameworkElement frameworkElement    = targetElement as BaseFrameworkElement;
                Size preferredSize = frameworkElement == null || !frameworkElement.IsViewObjectValid ? Size.Empty : frameworkElement.GetComputedBounds((Base2DElement)frameworkElement).Size;
                viewModel.SetViewRoot(this.SceneViewModel.DefaultView, targetElement, ancestorPropertyKey, correspondingNodePath.Node, preferredSize);
                viewModel.DefaultView.EnsureDesignSurfaceVisible();
            }
            if (!viewModel.IsEditable)
            {
                return;
            }
            SceneElement selectionToSet = viewModel.GetSceneNode(correspondingNodePath.Node) as SceneElement;

            viewModel.ElementSelectionSet.SetSelection(selectionToSet);
        }