private void AssociatedObject_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var item = VisualTreeHelperT.FindVisualParentOrSelf <ListBoxItem>(e.OriginalSource);

            if (item != null && (this.Command != null))
            {
                object commandParameter = this.CommandParameter;

                if (commandParameter == null)
                {
                    commandParameter = item.DataContext;
                }

                if (this.Command.CanExecute(commandParameter))
                {
                    this.Command.Execute(commandParameter);
                }
            }
        }
Esempio n. 2
0
        private void AssociatedObject_PreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            if (e.OriginalSource is ListBoxItem)
            {
                return;
            }

            var item = VisualTreeHelperT.FindVisualParentOrSelf<ListBoxItem>(e.OriginalSource);
            if (item != null)
            {
                if (this.AssociatedObject.SelectionMode == SelectionMode.Single)
                {
                    item.IsSelected = true;
                }
                else
                {
                    this.AssociatedObject.SelectedItems.Clear();
                    item.IsSelected = true;
                }
            }
        }