public void ValidateGroupRemoves() { RunOnUIThread.Execute(() => { var data = CreateNestedData(1 /* levels */, 3 /* groupsAtLevel */, 3 /* countAtLeaf */); var selectionModel = new SelectionModel(); selectionModel.Source = data; selectionModel.Select(1, 1); selectionModel.Select(1, 2); ValidateSelection(selectionModel, new List <IndexPath>() { Path(1, 1), Path(1, 2) }, new List <IndexPath>() { Path(), Path(1), }); Log.Comment("Remove before selected range: Removing item at group index 0"); data.RemoveAt(0); ValidateSelection(selectionModel, new List <IndexPath>() { Path(0, 1), Path(0, 2) }, new List <IndexPath>() { Path(), Path(0), }); Log.Comment("Remove after selected range: Removing item at group index 1"); data.RemoveAt(1); ValidateSelection(selectionModel, new List <IndexPath>() { Path(0, 1), Path(0, 2) }, new List <IndexPath>() { Path(), Path(0), }); Log.Comment("Remove group containing selected items"); data.RemoveAt(0); ValidateSelection(selectionModel, new List <IndexPath>()); }); }
protected override void OnKeyUp(KeyRoutedEventArgs e) { if (SelectionModel != null) { if (e.Key == VirtualKey.Escape) { SelectionModel.ClearSelection(); } else if (e.Key == VirtualKey.Space) { SelectionModel.Select(RepeatedIndex); } else if (!SelectionModel.SingleSelect) { var isShiftPressed = Window.Current.CoreWindow.GetAsyncKeyState(VirtualKey.Shift).HasFlag(Windows.UI.Core.CoreVirtualKeyStates.Down); var isCtrlPressed = Window.Current.CoreWindow.GetAsyncKeyState(VirtualKey.Control).HasFlag(Windows.UI.Core.CoreVirtualKeyStates.Down); if (e.Key == VirtualKey.A && isCtrlPressed) { SelectionModel.SelectAll(); } else if (isShiftPressed) { SelectionModel.SelectRangeFromAnchor(RepeatedIndex); } } } base.OnKeyUp(e); }
protected override void OnPointerPressed(PointerRoutedEventArgs e) { if (SelectionModel != null) { if (e.KeyModifiers.HasFlag(VirtualKeyModifiers.Shift) && !SelectionModel.SingleSelect) { if (e.KeyModifiers.HasFlag(VirtualKeyModifiers.Control)) { SelectionModel.DeselectRangeFromAnchor(RepeatedIndex); } else { SelectionModel.SelectRangeFromAnchor(RepeatedIndex); } } else if (e.KeyModifiers.HasFlag(VirtualKeyModifiers.Control)) { if (SelectionModel.IsSelected(RepeatedIndex).Value) { SelectionModel.Deselect(RepeatedIndex); } else { SelectionModel.Select(RepeatedIndex); } } else { SelectionModel.Select(RepeatedIndex); this.Focus(FocusState.Keyboard); } } base.OnPointerPressed(e); }
private void Select(SelectionModel manager, int groupIndex, int itemIndex, bool select) { Log.Comment((select ? "Selecting " : "DeSelecting ") + groupIndex + "." + itemIndex); if (select) { manager.Select(groupIndex, itemIndex); } else { manager.Deselect(groupIndex, itemIndex); } }
private void Select(SelectionModel manager, int index, bool select) { Log.Comment((select ? "Selecting " : "DeSelecting ") + index); if (select) { manager.Select(index); } else { manager.Deselect(index); } }
public void CanReplaceItem() { RunOnUIThread.Execute(() => { var data = new ObservableCollection <int>(Enumerable.Range(0, 10)); var selectionModel = new SelectionModel(); selectionModel.Source = data; selectionModel.Select(3); selectionModel.Select(4); selectionModel.Select(5); ValidateSelection(selectionModel, new List <IndexPath>() { Path(3), Path(4), Path(5), }, new List <IndexPath>() { Path() }); data[3] = 300; data[4] = 400; ValidateSelection(selectionModel, new List <IndexPath>() { Path(5), }, new List <IndexPath>() { Path() }); }); }
public void CanReadSelectedItemViaICustomPropertyProvider() { RunOnUIThread.Execute(() => { var selectionModel = new SelectionModel(); Log.Comment("Set the source to 10 items"); selectionModel.Source = Enumerable.Range(0, 10).ToList(); selectionModel.Select(3); var icpp = (ICustomPropertyProvider)selectionModel; var selectedItemProperty = icpp.GetCustomProperty("SelectedItem"); Verify.IsTrue(selectedItemProperty.CanRead); Verify.AreEqual(3, selectedItemProperty.GetValue(selectionModel)); }); }
public void ValidateGroupInserts() { RunOnUIThread.Execute(() => { var data = CreateNestedData(1 /* levels */, 3 /* groupsAtLevel */, 3 /* countAtLeaf */); var selectionModel = new SelectionModel(); selectionModel.Source = data; selectionModel.Select(1, 1); ValidateSelection(selectionModel, new List <IndexPath>() { Path(1, 1), }, new List <IndexPath>() { Path(), Path(1), }); Log.Comment("Insert before selected range: Inserting item at group index 0"); data.Insert(0, 100); ValidateSelection(selectionModel, new List <IndexPath>() { Path(2, 1) }, new List <IndexPath>() { Path(), Path(2), }); Log.Comment("Insert after selected range: Inserting item at group index 3"); data.Insert(3, 1000); ValidateSelection(selectionModel, new List <IndexPath>() { Path(2, 1) }, new List <IndexPath>() { Path(), Path(2), }); }); }
public void ValidateGroupClear() { RunOnUIThread.Execute(() => { var data = CreateNestedData(1 /* levels */, 3 /* groupsAtLevel */, 3 /* countAtLeaf */); var selectionModel = new SelectionModel(); selectionModel.Source = data; selectionModel.Select(1, 1); ValidateSelection(selectionModel, new List <IndexPath>() { Path(1, 1) }, new List <IndexPath>() { Path(), Path(1) }); (data[1] as IList).Clear(); ValidateSelection(selectionModel, new List <IndexPath>()); }); }
public void ValidateGroupReplaceLosesSelection() { RunOnUIThread.Execute(() => { var data = CreateNestedData(1 /* levels */, 3 /* groupsAtLevel */, 3 /* countAtLeaf */); var selectionModel = new SelectionModel(); selectionModel.Source = data; selectionModel.Select(1, 1); ValidateSelection(selectionModel, new List <IndexPath>() { Path(1, 1) }, new List <IndexPath>() { Path(), Path(1) }); data[1] = new ObservableCollection <int>(Enumerable.Range(0, 5)); ValidateSelection(selectionModel, new List <IndexPath>()); }); }
public void ValidateEventWhenInnerNodeChangesSelectionState() { RunOnUIThread.Execute(() => { bool selectionChangedRaised = false; var data = CreateNestedData(1 /* levels */, 3 /* groupsAtLevel */, 3 /* countAtLeaf */); var selectionModel = new SelectionModel(); selectionModel.Source = data; selectionModel.SelectionChanged += (sender, args) => { selectionChangedRaised = true; }; selectionModel.Select(1, 0); selectionModel.Select(1, 1); selectionModel.Select(1, 2); ValidateSelection(selectionModel, new List <IndexPath>() { Path(1, 0), Path(1, 1), Path(1, 2), Path(1) }, new List <IndexPath>() { Path(), }, 1 /* selectedInnerNodes */); Log.Comment("Inserting 1.0"); selectionChangedRaised = false; (data[1] as ObservableCollection <object>).Insert(0, 100); Verify.IsTrue(selectionChangedRaised, "SelectionChanged event was not raised"); ValidateSelection(selectionModel, new List <IndexPath>() { Path(1, 1), Path(1, 2), Path(1, 3), }, new List <IndexPath>() { Path(), Path(1), }); Log.Comment("Removing 1.0"); selectionChangedRaised = false; (data[1] as ObservableCollection <object>).RemoveAt(0); Verify.IsTrue(selectionChangedRaised, "SelectionChanged event was not raised"); ValidateSelection(selectionModel, new List <IndexPath>() { Path(1, 0), Path(1, 1), Path(1, 2), Path(1) }, new List <IndexPath>() { Path(), }, 1 /* selectedInnerNodes */); }); }
public void ValidateRemoves() { RunOnUIThread.Execute(() => { var data = new ObservableCollection <int>(Enumerable.Range(0, 10)); var selectionModel = new SelectionModel(); selectionModel.Source = data; selectionModel.Select(6); selectionModel.Select(7); selectionModel.Select(8); ValidateSelection(selectionModel, new List <IndexPath>() { Path(6), Path(7), Path(8) }, new List <IndexPath>() { Path() }); Log.Comment("Remove before selected range: Removing item at index 0"); data.RemoveAt(0); ValidateSelection(selectionModel, new List <IndexPath>() { Path(5), Path(6), Path(7) }, new List <IndexPath>() { Path() }); Log.Comment("Remove from before to middle of selected range: Removing items at index 3, 4, 5"); data.RemoveAt(3); data.RemoveAt(3); data.RemoveAt(3); ValidateSelection(selectionModel, new List <IndexPath>() { Path(3), Path(4) }, new List <IndexPath>() { Path() }); Log.Comment("Remove after selected range: Removing item at index 5"); data.RemoveAt(5); ValidateSelection(selectionModel, new List <IndexPath>() { Path(3), Path(4) }, new List <IndexPath>() { Path() }); }); }
public void ValidateInserts() { RunOnUIThread.Execute(() => { var data = new ObservableCollection <int>(Enumerable.Range(0, 10)); var selectionModel = new SelectionModel(); selectionModel.Source = data; selectionModel.Select(3); selectionModel.Select(4); selectionModel.Select(5); ValidateSelection(selectionModel, new List <IndexPath>() { Path(3), Path(4), Path(5), }, new List <IndexPath>() { Path() }); Log.Comment("Insert in selected range: Inserting 3 items at index 4"); data.Insert(4, 41); data.Insert(4, 42); data.Insert(4, 43); ValidateSelection(selectionModel, new List <IndexPath>() { Path(3), Path(7), Path(8), }, new List <IndexPath>() { Path() }); Log.Comment("Insert before selected range: Inserting 3 items at index 0"); data.Insert(0, 100); data.Insert(0, 101); data.Insert(0, 102); ValidateSelection(selectionModel, new List <IndexPath>() { Path(6), Path(10), Path(11), }, new List <IndexPath>() { Path() }); Log.Comment("Insert after selected range: Inserting 3 items at index 12"); data.Insert(12, 1000); data.Insert(12, 1001); data.Insert(12, 1002); ValidateSelection(selectionModel, new List <IndexPath>() { Path(6), Path(10), Path(11), }, new List <IndexPath>() { Path() }); }); }
public void Select() { SelectionModel.Select(GetGroupIndex(), RepeatedIndex); }