예제 #1
0
        public void CreateNewEventTrigger()
        {
            if (this.CurrentContainer == null)
            {
                return;
            }
            SceneViewModel    activeSceneViewModel = this.ActiveSceneViewModel;
            SceneDocument     document             = activeSceneViewModel.Document;
            ITriggerContainer currentContainer     = this.CurrentContainer;

            using (SceneEditTransaction editTransaction = document.CreateEditTransaction(StringTable.TriggerChangeUndoUnit))
            {
                IProjectContext projectContext = document.ProjectContext;
                IType           type           = projectContext.GetType(currentContainer.TargetElementType);
                if (type != null)
                {
                    TriggerSourceInformation triggerSource = (TriggerSourceInformation)TriggersHelper.GetDefaultEvent((ITypeResolver)projectContext, type);
                    if (triggerSource != (TriggerSourceInformation)null)
                    {
                        TriggerBaseNode trigger = TriggersHelper.CreateTrigger(triggerSource, activeSceneViewModel);
                        if (trigger != null)
                        {
                            int index = currentContainer.VisualTriggers.Count;
                            if (this.selectedItem != null)
                            {
                                index = this.selectedItem != this.noneTrigger ? currentContainer.VisualTriggers.IndexOf(this.selectedItem.SceneNode) + 1 : 0;
                            }
                            currentContainer.VisualTriggers.Insert(index, trigger);
                            this.TriggerToBeSelected = trigger;
                        }
                    }
                }
                editTransaction.Commit();
            }
        }
예제 #2
0
        public static TriggerBaseNode FindOrCreateTrigger(TriggerSourceInformation triggerSource, ITriggerContainer triggerContainer, SceneViewModel viewModel)
        {
            RoutedEventInformation eventInformation    = triggerSource as RoutedEventInformation;
            PropertyInformation    propertyInformation = triggerSource as PropertyInformation;

            foreach (TriggerBaseNode triggerBaseNode in (IEnumerable <TriggerBaseNode>)triggerContainer.VisualTriggers)
            {
                EventTriggerNode eventTriggerNode = triggerBaseNode as EventTriggerNode;
                TriggerNode      triggerNode      = triggerBaseNode as TriggerNode;
                if (eventTriggerNode != null && (TriggerSourceInformation)eventInformation != (TriggerSourceInformation)null && eventTriggerNode.RoutedEvent == eventInformation.RoutedEvent)
                {
                    return((TriggerBaseNode)eventTriggerNode);
                }
                if (triggerNode != null && (TriggerSourceInformation)propertyInformation != (TriggerSourceInformation)null && ((ITriggerConditionNode)triggerNode).PropertyKey == propertyInformation.DependencyProperty)
                {
                    return((TriggerBaseNode)triggerNode);
                }
            }
            TriggerBaseNode trigger = TriggersHelper.CreateTrigger(triggerSource, viewModel);

            if (trigger != null)
            {
                triggerContainer.VisualTriggers.Add(trigger);
            }
            return(trigger);
        }
예제 #3
0
        public void CreateNewPropertyTrigger()
        {
            if (this.CurrentContainer == null)
            {
                return;
            }
            ITriggerContainer        currentContainer         = this.CurrentContainer;
            SceneViewModel           activeSceneViewModel     = this.ActiveSceneViewModel;
            SceneDocument            document                 = activeSceneViewModel.Document;
            StyleNode                styleNode                = currentContainer as StyleNode;
            FrameworkTemplateElement frameworkTemplateElement = currentContainer as FrameworkTemplateElement;

            using (SceneEditTransaction editTransaction = document.CreateEditTransaction(StringTable.TriggerChangeUndoUnit))
            {
                TriggerSourceInformation triggerSource = (TriggerSourceInformation)null;
                if (styleNode != null || frameworkTemplateElement != null)
                {
                    triggerSource = (TriggerSourceInformation)TriggersHelper.GetDefaultProperty(currentContainer.TargetElementType, document.DocumentContext);
                }
                if (triggerSource != (TriggerSourceInformation)null)
                {
                    TriggerBaseNode trigger = TriggersHelper.CreateTrigger(triggerSource, activeSceneViewModel);
                    if (trigger != null)
                    {
                        int index = currentContainer.VisualTriggers.Count;
                        if (this.selectedItem != null)
                        {
                            index = this.selectedItem != this.noneTrigger ? currentContainer.VisualTriggers.IndexOf(this.selectedItem.SceneNode) + 1 : 0;
                        }
                        currentContainer.VisualTriggers.Insert(index, trigger);
                        activeSceneViewModel.SetActiveTrigger(trigger);
                    }
                }
                editTransaction.Commit();
            }
        }