protected override BaseFrameworkElement CreateElementOnStartDrag() { BaseFrameworkElement frameworkElement = (BaseFrameworkElement)null; using (this.ActiveSceneViewModel.ForceBaseValue()) { PerformanceUtility.StartPerformanceSequence(PerformanceEvent.ShapeCreateBehaviorOnDragCreateElement); frameworkElement = (BaseFrameworkElement)this.ActiveSceneViewModel.CreateSceneNode(this.elementType); if (this.ActiveSceneInsertionPoint.CanInsert((ITypeId)frameworkElement.Type)) { IList <SceneNode> nodeTreeOnInsertion = this.typeInstantiator.CreateNodeTreeOnInsertion((SceneNode)frameworkElement); this.typeInstantiator.ApplyBeforeInsertionDefaultsToElements(nodeTreeOnInsertion, (SceneNode)frameworkElement, new DefaultTypeInstantiator.SceneElementNamingCallback(DefaultTypeInstantiator.TypeNameCallback)); this.ActiveSceneInsertionPoint.Insert((SceneNode)frameworkElement); this.UpdateEditTransaction(); this.typeInstantiator.ApplyAfterInsertionDefaultsToElements(nodeTreeOnInsertion, (SceneNode)frameworkElement); this.ActiveSceneViewModel.ElementSelectionSet.SetSelection(DefaultTypeInstantiator.GetSelectionTarget((SceneNode)frameworkElement)); this.ActiveSceneViewModel.CanonicalizeViewState(SceneUpdateTypeFlags.Completing); } PerformanceUtility.EndPerformanceSequence(PerformanceEvent.ShapeCreateBehaviorOnDragCreateElement); } return(frameworkElement); }
public virtual SceneNode CreateInstance(ITypeId instanceType, ISceneInsertionPoint insertionPoint, Rect rect, OnCreateInstanceAction action) { PerformanceUtility.StartPerformanceSequence(PerformanceEvent.PropertyInspectorFromCreate); PerformanceUtility.MeasurePerformanceUntilRender(PerformanceEvent.CreateElement); SceneView sceneView = this.sceneView; if (sceneView == null || !sceneView.IsEditable || insertionPoint == null) { return((SceneNode)null); } SceneNode rawInstance = this.CreateRawInstance(instanceType); if (rawInstance == null || !insertionPoint.CanInsert((ITypeId)rawInstance.Type)) { return((SceneNode)null); } if (rect.IsEmpty) { rect = new Rect(0.0, 0.0, double.NaN, double.NaN); } if (double.IsInfinity(rect.Width)) { rect.Width = double.NaN; } if (double.IsInfinity(rect.Height)) { rect.Height = double.NaN; } using (this.ViewModel.ForceBaseValue()) { using (SceneEditTransaction editTransaction = this.ViewModel.CreateEditTransaction(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.UndoUnitCreateControlFormat, new object[1] { (object)instanceType.Name }))) { IExpandable expandable = insertionPoint.SceneElement as IExpandable; if (expandable != null) { insertionPoint.SceneNode.SetValue(expandable.ExpansionProperty, (object)true); } bool flag = this.ShouldUseDefaultInitializer && Enumerable.Any <FeatureProvider>(DefaultTypeInstantiator.GetDefaultInitializers(rawInstance)); IList <SceneNode> nodes = (IList <SceneNode>)null; if (!flag) { nodes = this.CreateNodeTreeOnInsertion(rawInstance); this.ApplyBeforeInsertionDefaultsToElements(nodes, rawInstance, new DefaultTypeInstantiator.SceneElementNamingCallback(DefaultTypeInstantiator.TypeNameCallback)); } SceneNode layoutTarget = DefaultTypeInstantiator.GetLayoutTarget(rawInstance); SceneElement selectionTarget = DefaultTypeInstantiator.GetSelectionTarget(rawInstance); this.ViewModel.ElementSelectionSet.Clear(); insertionPoint.Insert(rawInstance); editTransaction.Update(); this.ApplyDefaultInitializers(rawInstance); if (action != null) { action(rawInstance); editTransaction.Update(); } if (!flag) { this.ApplyAfterInsertionDefaultsToElements(nodes, rawInstance); } SceneElement sceneElement1 = layoutTarget as SceneElement; EffectNode effectNode = layoutTarget as EffectNode; if (sceneElement1 != null && sceneElement1.IsViewObjectValid) { if (selectionTarget != null) { this.ViewModel.ElementSelectionSet.SetSelection(selectionTarget); } this.SetLayout(insertionPoint, rect, rawInstance, layoutTarget, editTransaction); } else if (effectNode != null) { this.ViewModel.ChildPropertySelectionSet.SetSelection((SceneNode)effectNode); } else { for (SceneNode sceneNode = layoutTarget; sceneNode != null; sceneNode = sceneNode.Parent) { SceneElement sceneElement2 = sceneNode as SceneElement; if (sceneElement2 != null && sceneElement2.Visual != null && sceneElement2.Visual is IViewVisual) { this.sceneView.EnsureVisible(sceneElement2.Visual); break; } } } if (this.ViewModel.DesignerContext.AmbientPropertyManager != null) { this.ViewModel.DesignerContext.AmbientPropertyManager.ApplyAmbientProperties(rawInstance); } editTransaction.Commit(); } } return(rawInstance); }