public override void SelectElement(SceneElement element, SceneNodeProperty editingProperty) { if (element == null || editingProperty == null) { return; } BehaviorHelper.CreateAndSetElementNameBinding(editingProperty, (SceneNode)element); }
public static SceneNode CreateTrigger(SceneNode targetNode, IType triggerType) { ProjectContext projectContext = ProjectContext.GetProjectContext(targetNode.ProjectContext); BehaviorHelper.EnsureSystemWindowsInteractivityReferenced((ITypeResolver)projectContext); targetNode.DesignerContext.ViewUpdateManager.RebuildPostponedViews(); using (SceneEditTransaction editTransaction = targetNode.ViewModel.CreateEditTransaction(StringTable.CreateTriggerActionUndoString)) { SceneNode sceneNode1 = targetNode; ISceneNodeCollection <SceneNode> collectionForProperty = sceneNode1.GetCollectionForProperty(BehaviorHelper.BehaviorTriggersProperty); BehaviorTriggerBaseNode behaviorTriggerBaseNode = (BehaviorTriggerBaseNode)null; SceneViewModel viewModel = targetNode.ViewModel; object triggerAttribute = BehaviorHelper.CreateTriggerFromDefaultTriggerAttribute((IEnumerable)TypeUtilities.GetAttributes(triggerType.RuntimeType), targetNode.TargetType); if (triggerAttribute != null) { behaviorTriggerBaseNode = (BehaviorTriggerBaseNode)viewModel.CreateSceneNode(triggerAttribute); } if (behaviorTriggerBaseNode == null) { BehaviorEventTriggerNode eventTriggerNode = (BehaviorEventTriggerNode)sceneNode1.ViewModel.CreateSceneNode(ProjectNeutralTypes.BehaviorEventTrigger); string result; if (!PlatformNeutralAttributeHelper.TryGetAttributeValue <string>(targetNode.TargetType, PlatformTypes.DefaultEventAttribute, "Name", out result)) { result = "Loaded"; } eventTriggerNode.EventName = result; behaviorTriggerBaseNode = (BehaviorTriggerBaseNode)eventTriggerNode; } bool flag = false; viewModel.BehaviorSelectionSet.Clear(); foreach (SceneNode sceneNode2 in (IEnumerable <SceneNode>)collectionForProperty) { if (BehaviorHelper.CompareTriggerNodes(behaviorTriggerBaseNode.DocumentNode as DocumentCompositeNode, sceneNode2.DocumentNode as DocumentCompositeNode)) { behaviorTriggerBaseNode = (BehaviorTriggerBaseNode)sceneNode2; flag = true; break; } } if (!flag) { collectionForProperty.Add((SceneNode)behaviorTriggerBaseNode); } BehaviorTriggerActionNode triggerActionNode = (BehaviorTriggerActionNode)sceneNode1.ViewModel.CreateSceneNode((ITypeId)triggerType); if (projectContext.IsCapabilitySet(PlatformCapability.SupportsAttachingToRootElements) && ProjectNeutralTypes.BehaviorTargetedTriggerAction.IsAssignableFrom((ITypeId)triggerActionNode.Type) && targetNode.ViewModel.ActiveEditingContainer.Equals((object)targetNode)) { IProperty property = projectContext.ResolveProperty(BehaviorTargetedTriggerActionNode.BehaviorTargetObjectProperty); if (property != null) { BehaviorHelper.CreateAndSetElementNameBinding((IPropertyId)property, (SceneNode)triggerActionNode, targetNode); } } behaviorTriggerBaseNode.Actions.Add((SceneNode)triggerActionNode); viewModel.BehaviorSelectionSet.SetSelection((BehaviorBaseNode)triggerActionNode); editTransaction.Commit(); return((SceneNode)triggerActionNode); } }
protected override SceneNode InternalCreateInstance(ISceneInsertionPoint insertionPoint, Rect rect, OnCreateInstanceAction action) { ProjectContext projectContext = ProjectContext.GetProjectContext(insertionPoint.SceneNode.ProjectContext); if (!this.EnsureTypeReferenced(projectContext)) { return((SceneNode)null); } BehaviorHelper.EnsureSystemWindowsInteractivityReferenced((ITypeResolver)projectContext); insertionPoint.SceneNode.DesignerContext.ViewUpdateManager.RebuildPostponedViews(); SceneViewModel viewModel = insertionPoint.SceneNode.ViewModel; using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.UndoUnitCreateControlFormat, new object[1] { (object)this.Name }))) { viewModel.BehaviorSelectionSet.Clear(); BehaviorBaseNode selectionToSet = (BehaviorBaseNode)base.InternalCreateInstance(insertionPoint, rect, action); ISceneNodeCollection <SceneNode> collectionForProperty = selectionToSet.GetCollectionForProperty(BehaviorHelper.BehaviorTriggersProperty); foreach (IProperty property in selectionToSet.GetProperties()) { if (PlatformTypes.ICommand.IsAssignableFrom((ITypeId)property.PropertyType)) { object triggerAttribute = BehaviorHelper.CreateTriggerFromDefaultTriggerAttribute((IEnumerable)property.Attributes, insertionPoint.SceneNode.TargetType); if (triggerAttribute != null) { BehaviorTriggerBaseNode behaviorTriggerBaseNode = (BehaviorTriggerBaseNode)viewModel.CreateSceneNode(triggerAttribute); InvokeCommandActionNode commandActionNode = (InvokeCommandActionNode)viewModel.CreateSceneNode(ProjectNeutralTypes.InvokeCommandAction); commandActionNode.CommandName = property.Name; behaviorTriggerBaseNode.Actions.Add((SceneNode)commandActionNode); if (ProjectNeutralTypes.BehaviorEventTriggerBase.IsAssignableFrom((ITypeId)behaviorTriggerBaseNode.Type)) { BehaviorHelper.CreateAndSetElementNameBinding(BehaviorEventTriggerBaseNode.BehaviorSourceObjectProperty, (SceneNode)behaviorTriggerBaseNode, insertionPoint.SceneNode); } collectionForProperty.Add((SceneNode)behaviorTriggerBaseNode); } } } viewModel.BehaviorSelectionSet.SetSelection(selectionToSet); editTransaction.Commit(); return((SceneNode)selectionToSet); } }
private SceneNode InsertTrigger(BehaviorTriggerBaseNode triggerNode) { BehaviorTriggerActionNode triggerActionNode1 = (BehaviorTriggerActionNode)triggerNode.Actions[0]; DocumentCompositeNode documentCompositeNode = (DocumentCompositeNode)triggerNode.DocumentNode; IProjectContext projectContext = triggerNode.ProjectContext; SceneNode sceneNode = this.InsertionPoint.SceneNode; ISceneNodeCollection <SceneNode> collectionForProperty = sceneNode.GetCollectionForProperty(BehaviorHelper.BehaviorTriggersProperty); BehaviorTriggerBaseNode behaviorTriggerBaseNode = BehaviorHelper.FindMatchingTriggerNode((DocumentNode)documentCompositeNode, collectionForProperty); if (behaviorTriggerBaseNode != null) { BehaviorTriggerActionNode triggerActionNode2 = (BehaviorTriggerActionNode)this.ViewModel.GetSceneNode(triggerActionNode1.DocumentNode.Clone(this.ViewModel.Document.DocumentContext)); behaviorTriggerBaseNode.Actions.Add((SceneNode)triggerActionNode2); triggerActionNode1 = triggerActionNode2; } else { behaviorTriggerBaseNode = triggerNode; collectionForProperty.Add((SceneNode)behaviorTriggerBaseNode); } if (projectContext.IsCapabilitySet(PlatformCapability.SupportsAttachingToRootElements) && sceneNode.ViewModel.ActiveEditingContainer.Equals((object)sceneNode)) { IProperty property = projectContext.ResolveProperty(BehaviorTargetedTriggerActionNode.BehaviorTargetObjectProperty); if (property != null) { foreach (BehaviorTriggerActionNode triggerActionNode2 in (IEnumerable <SceneNode>)behaviorTriggerBaseNode.Actions) { if (ProjectNeutralTypes.BehaviorTargetedTriggerAction.IsAssignableFrom((ITypeId)triggerActionNode2.Type)) { BehaviorHelper.CreateAndSetElementNameBinding((IPropertyId)property, (SceneNode)triggerActionNode2, sceneNode); } } } } BehaviorEventTriggerNode eventTriggerNode = behaviorTriggerBaseNode as BehaviorEventTriggerNode; if (eventTriggerNode != null) { BehaviorEventTriggerNode.FixUpEventName(eventTriggerNode); } return((SceneNode)triggerActionNode1); }