public void Select(bool select) { if (SelectionModel != null) { var indexPath = GetIndexPath(); if (select) { SelectionModel.SelectAt(indexPath); } else { SelectionModel.DeselectAt(indexPath); } } }
protected override void OnKeyUp(KeyEventArgs e) { var indexPath = GetIndexPath(); Debug.WriteLine("OnKeyUp:" + indexPath.ToString()); if (SelectionModel != null) { if (e.Key == Key.Escape) { SelectionModel.ClearSelection(); } else if (e.Key == Key.Space) { SelectionModel.SelectAt(indexPath); } else if (!SelectionModel.SingleSelect) { var isShiftPressed = Keyboard.Modifiers.HasFlag(ModifierKeys.Shift); var isCtrlPressed = Keyboard.Modifiers.HasFlag(ModifierKeys.Control); if (e.Key == Key.A && isCtrlPressed) { SelectionModel.SelectAll(); } else if (isCtrlPressed && e.Key == Key.Space) { if (SelectionModel.IsSelectedAt(indexPath).Value) { SelectionModel.DeselectAt(indexPath); } else { SelectionModel.SelectAt(indexPath); } } else if (isShiftPressed) { SelectionModel.SelectRangeFromAnchorTo(GetIndexPath()); } } } base.OnKeyUp(e); }
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { if (!e.Handled) { var indexPath = GetIndexPath(); Debug.WriteLine("OnPointerPressed:" + indexPath.ToString()); if (SelectionModel != null) { if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift) && !SelectionModel.SingleSelect) { if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { SelectionModel.DeselectRangeFromAnchorTo(GetIndexPath()); } else { SelectionModel.SelectRangeFromAnchorTo(GetIndexPath()); } } else if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { var path = GetIndexPath(); if (SelectionModel.IsSelectedAt(path).Value) { SelectionModel.SelectAt(path); } else { SelectionModel.SelectAt(path); } } else { SelectionModel.SelectAt(GetIndexPath()); this.Focus(); } } e.Handled = true; base.OnMouseLeftButtonDown(e); } }