private void SelectRow(FileSystemElement fse) { if (SelectedItems.Contains(fse)) { return; } var container = (ContentPresenter)ItemsSourceRowHitbox.ContainerFromItem(fse); if (container == null) { return; } var hitbox = (FrameworkElement)VisualTreeHelper.GetChild(container, 0); SelectedItems.Add(fse); selectedElements.Add(hitbox); //When item which is going to be selected and is focused apply different style if (fse == FocusedItem) { hitbox.Style = (Style)Resources["RowSelectedFocusedStyle"]; } else { hitbox.Style = (Style)Resources["RowSelectedStyle"]; } }
private void TryScrollFocusSelect(FileSystemElement fse) { //Check if the element is even rendered var container = (ContentPresenter)ItemsSourceRowHitbox.ContainerFromItem(fse); if (container == null) { ScrollTo(fse); return; } var childTransform = container.TransformToVisual(ScrollViewer); var rectangle = childTransform.TransformBounds(new Rect(new Point(0, 0), container.RenderSize)); var scrollViewerRect = new Rect(new Point(0, 0), ScrollViewer.RenderSize); //Check if the elements Rect intersects with that of the scrollviewer's scrollViewerRect.Intersect(rectangle); //Not in view if (scrollViewerRect.IsEmpty) { ScrollTo(fse); } var hitbox = (FrameworkElement)VisualTreeHelper.GetChild(container, 0); ToggleSelect(fse, hitbox); FocusRow(fse, hitbox); }
private void DeselectRow(FileSystemElement fse) { var container = (ContentPresenter)ItemsSourceRowHitbox.ContainerFromItem(fse); var hitbox = (FrameworkElement)VisualTreeHelper.GetChild(container, 0); SelectedItems.Remove(fse); selectedElements.Remove(hitbox); StyleHitbox(fse, hitbox, ROW_DEFAULT_STYLE_NAME); }
private void ApplySelectedStyle(FileSystemElement fse) { var container = (ContentPresenter)ItemsSourceRowHitbox.ContainerFromItem(fse); if (container == null) { return; } var hitbox = (FrameworkElement)VisualTreeHelper.GetChild(container, 0); selectedElements.Add(hitbox); //When item which is going to be selected is focused apply different style StyleHitbox(hitbox, "RowSelected"); }
private void ToggleSelect(FileSystemElement fse) { var container = (ContentPresenter)ItemsSourceRowHitbox.ContainerFromItem(fse); var hitbox = (FrameworkElement)VisualTreeHelper.GetChild(container, 0); if (SelectedItems.Contains(fse)) { DeselectRow(fse, hitbox); return; } SelectedItems.Add(fse); selectedElements.Add(hitbox); StyleHitbox(fse, hitbox, ROW_SELECTED_STYLE_NAME); }
private void FocusRow(FileSystemElement fse, bool usedKeyboard = false) { //Remove focus highlight from old row //If there has already been a focused element if (focusedRow != null) { if (SelectedItems.Contains(FocusedItem)) { focusedRow.Style = (Style)Resources["RowSelectedStyle"]; } else { focusedRow.Style = (Style)Resources["RowDefaultStyle"]; } } //Scroll to focused item when the user navigates through files with the keyboard if (usedKeyboard) { ScrollTo(fse); } //Fetch row (border) from hitboxes (see xaml) var container = (ContentPresenter)ItemsSourceRowHitbox.ContainerFromItem(fse); if (container == null) { return; } var row = (FrameworkElement)VisualTreeHelper.GetChild(container, 0); //Store FileSystemElement(for checking if its selected) and Border (for styling) FocusedItem = fse; focusedRow = row; //Apply focused style to new row if (SelectedItems.Contains(FocusedItem)) { focusedRow.Style = (Style)Resources["RowSelectedFocusedStyle"]; } else { focusedRow.Style = (Style)Resources["RowDefaultFocusedStyle"]; } }
private void SelectRowsBetween(FileSystemElement fse) { var lastTappedRowIndex = FocusedItem == null ? 0 : ItemsSource.IndexOf(FocusedItem); //SelectedItems.Count == 0 ? -1 : ItemsSource.IndexOf(SelectedItems.Last()); var tappedRowIndex = ItemsSource.IndexOf(fse); var from = Math.Min(lastTappedRowIndex, tappedRowIndex); var to = Math.Max(lastTappedRowIndex, tappedRowIndex); for (int i = from; i <= to; i++) { //if (i == lastTappedRowIndex) continue; var item = ItemsSource[i]; var container = (ContentPresenter)ItemsSourceRowHitbox.ContainerFromItem(item); var row = (FrameworkElement)VisualTreeHelper.GetChild(container, 0); if (!SelectedItems.Contains(item)) { ToggleSelect(item, row); } } }