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); } } }
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; } } }