private void ListViewItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var listViewItem = sender as ListViewItem; if (listViewItem == null) { return; } var topItem = listViewItem.Content as StatisticsItem; if (topItem == null) { return; } var fileNode = ((TreeGridNodeViewModel)TreeGrid.Root).GetChild(IoHelpers.SplitPath(topItem.Path)[1]); if (fileNode == null) { return; } var item = TreeGrid.ItemContainerGenerator.ContainerFromItem(fileNode) as ListViewItem; if (item == null) { return; } TreeGrid.SelectedItems.Clear(); TreeGrid.Focus(); item.Focus(); item.IsSelected = true; Keyboard.Focus(item); TreeGrid.ScrollIntoView(item); }
/// <summary> /// Let Renderer decide whether the parent grid should be allowed to handle keys and prevent /// the key event from being handled by the visual UIElement for this renderer. If this method /// returns true the parent grid will handle arrow keys and set the Handled flag in the event /// data. Keys that the grid does not handle will be ignored and be routed to the UIElement /// for this renderer. /// </summary> /// <param name="e">A <see cref="KeyEventArgs" /> object.</param> /// <returns> /// True if the parent grid should be allowed to handle keys; false otherwise. /// </returns> protected override bool ShouldGridTryToHandleKeyDown(KeyEventArgs e) { #if WPF if (!HasCurrentCellState || !IsInEditing) { return(true); } var currentCellUiElement = (MaskedTextBox)CurrentCellRendererElement; switch (e.Key) { case Key.Escape: { currentCellUiElement.ClearValue(MaskedTextBox.ValueProperty); return(true); } case Key.F2: { if (!IsInEditing) { TreeGrid.Focus(); } return(true); } case Key.A: return(SelectionHelper.CheckControlKeyPressed() && !IsInEditing); case Key.Left: return(currentCellUiElement.SelectionStart == currentCellUiElement.SelectionLength && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.Right: return(currentCellUiElement.CaretIndex >= currentCellUiElement.Text.Length && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.Home: return(currentCellUiElement.SelectionStart == currentCellUiElement.SelectionLength && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.End: return(currentCellUiElement.CaretIndex == currentCellUiElement.Text.Length && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); } #else if (!HasCurrentCellState) { return(true); } if (!IsInEditing) { ProcessPreviewTextInput(e); if (!(CurrentCellRendererElement is SfMaskedEdit)) { return(true); } } var currentCellUiElement = (SfMaskedEdit)CurrentCellRendererElement; switch (e.Key) { case Key.Escape: { currentCellUiElement.ClearValue(SfMaskedEdit.TextProperty); return(true); } } #endif return(base.ShouldGridTryToHandleKeyDown(e)); }
/// <summary> /// Sets the focus to the specified current cell uielement. /// </summary> /// <param name="uiElement"> /// Specifies the corresponding current cell uielement. /// </param> /// <param name="needToFocus"> /// Decides whether the focus set to current cell uielement. /// </param> protected virtual void SetFocus(FrameworkElement uiElement, bool needToFocus) { if (uiElement != null && IsFocusable) { UIElement uielement; var focusedElement = FocusManagerHelper.GetFocusedUIElement(CurrentCellRendererElement); uielement = focusedElement ?? uiElement; TreeGridColumn column = null; if (needToFocus) { var columnIndex = TreeGrid.ResolveToGridVisibleColumnIndex(CurrentCellIndex.ColumnIndex); column = TreeGrid.Columns[columnIndex]; } //SupportsRenderOptimization condition checked to move the Focus always to CheckBox instead of DataGrid - WPF-22403 if (needToFocus && (IsInEditing || column.CanFocus() || !SupportsRenderOptimization)) { if (IsFocused) { #if WPF if (!uielement.IsFocused) { uielement.Focusable = true; Keyboard.Focus(uielement); } #endif return; } #if WPF uielement.Focus(); #else if (uielement is Control) { (uielement as Control).Focus(FocusState.Programmatic); isfocused = false; return; } #endif isfocused = true; } else { #if WPF this.TreeGrid.Focus(); #else this.treeGrid.Focus(FocusState.Programmatic); #endif isfocused = false; } } else { #if WPF TreeGrid.Focus(); #else TreeGrid.Focus(FocusState.Programmatic); #endif isfocused = false; } }