Example #1
0
        protected override void OnPreviewKeyDown(KeyEventArgs e)
        {
            if (TryChangeSelectedItem(e))
            {
                e.Handled = true;
                return;
            }

            if (IsDropDownOpen && e.Key == Key.Enter)
            {
                AddToSelectedItems(SelectedItem);
            }
            else if (!IsDropDownOpen && e.Key == Key.Back &&
                     string.IsNullOrEmpty(editableTextBox.Text))
            {
                RemoveFromSelectedItems(SelectedItems.LastOrDefault());
            }
            else if (!IsDropDownOpen && e.Key == Key.Space && Keyboard.Modifiers == ModifierKeys.Control)
            {
                IsDropDownOpen = true;
                e.Handled      = true;
                return;
            }

            base.OnPreviewKeyDown(e);
        }
Example #2
0
        private void SelectedItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems != null)
            {
                foreach (var item in e.NewItems)
                {
                    CurrentItem = (T)item;
                }
            }
            else if (e.Action == NotifyCollectionChangedAction.Remove && e.OldItems != null)
            {
                CurrentItem = SelectedItems.LastOrDefault();
            }

            OnSelectedItemsChanged(e);
        }
Example #3
0
        /// <inheritdoc />
        protected override void SelectedContentCollectionChanged(NotifyCollectionChangedAction action)
        {
            base.SelectedContentCollectionChanged(action);

            if (action == NotifyCollectionChangedAction.Reset)
            {
                Controller.AdornerService.ClearSelection().Forget();
                return;
            }

            LastSelectedElement = SelectedItems.LastOrDefault();
            if (LastSelectedElement != null)
            {
                // Update active root
                ActiveRoot = LastSelectedElement.GetRootElementViewModel();
            }
            if (ActiveRoot != null)
            {
                // Select adorners (for the active root only)
                var elements = SelectedItems.Where(e => e.AssetSideUIElement.FindVisualRoot().Id == ActiveRoot.Id.ObjectId);
                elements.ForEach(e => e.SelectAdorner().Forget());
            }
        }