private void OnListBoxPreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { ListBoxItem item = VisualTreeUtils.FindVisualAncestor <ListBoxItem>(e.OriginalSource as DependencyObject); if (item != null) { this.SelectedListItem = item.Content as ExpandableItemWrapper; } }
private void OnListBoxPreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { ListBoxItem item = VisualTreeUtils.FindVisualAncestor<ListBoxItem>(e.OriginalSource as DependencyObject); if (item != null) { this.SelectedListItem = item.Content as ExpandableItemWrapper; } }
private void OnExpandCollapseButtonClicked(object sender, RoutedEventArgs e) { ToggleButton button = (ToggleButton)sender; ListBox listBox = VisualTreeUtils.FindVisualAncestor <ListBox>(button); ExpandableItemWrapper wrapper = (ExpandableItemWrapper)listBox.SelectedItem; wrapper.IsExpanded = button.IsChecked.Value; this.ViewStateService.StoreViewState(wrapper.Item, ExpandViewStateKey, button.IsChecked.Value); if ((wrapper.IsExpanded && this.Designer.ShouldCollapseAll) || !wrapper.IsExpanded && this.Designer.ShouldExpandAll) { // Pin the item so that it can still be expanded / collapsed when CollapseAll / ExpandAll is enabled wrapper.IsPinned = true; } }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values[0] != DependencyProperty.UnsetValue && values[1] != DependencyProperty.UnsetValue) { bool isExpanded = (bool)values[0]; bool isPinned = (bool)values[1]; bool shouldExpandAll = (bool)values[2]; bool shouldCollapseAll = (bool)values[3]; ExpandableItemWrapper wrapper = (ExpandableItemWrapper)values[4]; if ((!shouldExpandAll || isExpanded) && (!shouldCollapseAll || !isExpanded)) { wrapper.SetPinState(false); } return(ViewUtilities.ShouldShowExpanded(isExpanded, shouldExpandAll, shouldCollapseAll, wrapper.IsPinned)); } else { return(false); } }
public TransitionDesigner() { InitializeComponent(); this.TransitionsSharingTrigger = new ObservableCollection <ExpandableItemWrapper>(); this.Loaded += (sender, e) => { if (!this.isPopulated) { this.isPopulated = true; this.TransitionsSharingTrigger.CollectionChanged += OnTransitionsCollectionChanged; this.ModelItem.PropertyChanged += OnModelItemPropertyChanged; this.parentStateModelItem = StateContainerEditor.GetParentStateModelItemForTransition(this.ModelItem); this.parentStateModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection.CollectionChanged += OnTransitionsModelItemCollectionChanged; ExpandableItemWrapper selectedItem = this.UpdateTransitionsSharingTrigger(); if (null != selectedItem) { this.SelectedTransition = selectedItem; } } }; this.Unloaded += (sender, e) => { if (this.isPopulated) { this.isPopulated = false; this.TransitionsSharingTrigger.Clear(); this.TransitionsSharingTrigger.CollectionChanged -= OnTransitionsCollectionChanged; this.ModelItem.PropertyChanged -= OnModelItemPropertyChanged; this.parentStateModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection.CollectionChanged -= OnTransitionsModelItemCollectionChanged; this.SelectedTransition = null; this.parentStateModelItem = null; } }; }
private ExpandableItemWrapper UpdateTransitionsSharingTrigger() { ExpandableItemWrapper wrapper = null; if (!this.suppressUpdatingTransitionsSharingTrigger) { this.TransitionsSharingTrigger.Clear(); bool expandTargetTransition = true; object expandCollapseTargetViewState = this.ViewStateService.RetrieveViewState(this.ModelItem, ExpandViewStateKey); if (expandCollapseTargetViewState != null) { expandTargetTransition = (bool)expandCollapseTargetViewState; } wrapper = new ExpandableItemWrapper() { Item = this.ModelItem, IsExpanded = expandTargetTransition }; ModelItem triggerModelItem = this.ModelItem.Properties[TriggerPropertyName].Value; if (triggerModelItem != null) { foreach (ModelItem transitionModelItem in this.parentStateModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection) { if (transitionModelItem != this.ModelItem) { if (triggerModelItem == transitionModelItem.Properties[TriggerPropertyName].Value) { bool expandTransition = false; object expandCollapseViewState = this.ViewStateService.RetrieveViewState(transitionModelItem, ExpandViewStateKey); if (expandCollapseViewState != null) { expandTransition = (bool)expandCollapseViewState; } this.TransitionsSharingTrigger.Add(new ExpandableItemWrapper() { Item = transitionModelItem, IsExpanded = expandTransition }); } } else { this.TransitionsSharingTrigger.Add(wrapper); } } } // Connectors starting from the same point should share the same trigger else { PointCollection thisPointCollection = this.ViewStateService.RetrieveViewState(this.ModelItem, StateContainerEditor.ConnectorLocationViewStateKey) as PointCollection; if (thisPointCollection != null && thisPointCollection.Count > 1) { foreach (ModelItem transitionModelItem in this.parentStateModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection) { if (transitionModelItem != this.ModelItem) { PointCollection pointCollection = this.ViewStateService.RetrieveViewState(transitionModelItem, StateContainerEditor.ConnectorLocationViewStateKey) as PointCollection; if (pointCollection != null && pointCollection.Count > 0) { if (pointCollection[0].IsEqualTo(thisPointCollection[0])) { Fx.Assert(transitionModelItem.Properties[TriggerPropertyName].Value == null, "Transition trigger should be null."); bool expandTransition = false; object expandCollapseViewState = this.ViewStateService.RetrieveViewState(transitionModelItem, ExpandViewStateKey); if (expandCollapseViewState != null) { expandTransition = (bool)expandCollapseViewState; } this.TransitionsSharingTrigger.Add(new ExpandableItemWrapper() { Item = transitionModelItem, IsExpanded = expandTransition }); } } } else { this.TransitionsSharingTrigger.Add(wrapper); } } } } } return(wrapper); }
private ExpandableItemWrapper UpdateTransitionsSharingTrigger() { ExpandableItemWrapper wrapper = null; if (!this.suppressUpdatingTransitionsSharingTrigger) { this.TransitionsSharingTrigger.Clear(); bool expandTargetTransition = true; object expandCollapseTargetViewState = this.ViewStateService.RetrieveViewState(this.ModelItem, ExpandViewStateKey); if (expandCollapseTargetViewState != null) { expandTargetTransition = (bool)expandCollapseTargetViewState; } wrapper = new ExpandableItemWrapper() { Item = this.ModelItem, IsExpanded = expandTargetTransition }; ModelItem triggerModelItem = this.ModelItem.Properties[TriggerPropertyName].Value; if (triggerModelItem != null) { foreach (ModelItem transitionModelItem in this.parentStateModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection) { if (transitionModelItem != this.ModelItem) { if (triggerModelItem == transitionModelItem.Properties[TriggerPropertyName].Value) { bool expandTransition = false; object expandCollapseViewState = this.ViewStateService.RetrieveViewState(transitionModelItem, ExpandViewStateKey); if (expandCollapseViewState != null) { expandTransition = (bool)expandCollapseViewState; } this.TransitionsSharingTrigger.Add(new ExpandableItemWrapper() { Item = transitionModelItem, IsExpanded = expandTransition }); } } else { this.TransitionsSharingTrigger.Add(wrapper); } } } // Connectors starting from the same point should share the same trigger else { PointCollection thisPointCollection = this.ViewStateService.RetrieveViewState(this.ModelItem, StateContainerEditor.ConnectorLocationViewStateKey) as PointCollection; if (thisPointCollection != null && thisPointCollection.Count > 1) { foreach (ModelItem transitionModelItem in this.parentStateModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection) { if (transitionModelItem != this.ModelItem) { PointCollection pointCollection = this.ViewStateService.RetrieveViewState(transitionModelItem, StateContainerEditor.ConnectorLocationViewStateKey) as PointCollection; if (pointCollection != null && pointCollection.Count > 0) { if (pointCollection[0].IsEqualTo(thisPointCollection[0])) { Fx.Assert(transitionModelItem.Properties[TriggerPropertyName].Value == null, "Transition trigger should be null."); bool expandTransition = false; object expandCollapseViewState = this.ViewStateService.RetrieveViewState(transitionModelItem, ExpandViewStateKey); if (expandCollapseViewState != null) { expandTransition = (bool)expandCollapseViewState; } this.TransitionsSharingTrigger.Add(new ExpandableItemWrapper() { Item = transitionModelItem, IsExpanded = expandTransition }); } } } else { this.TransitionsSharingTrigger.Add(wrapper); } } } } } return wrapper; }