public ListBoxPageViewModel() { Items = new ObservableCollection <string>(Enumerable.Range(1, 10000).Select(i => GenerateItem())); Selection = new SelectionModel <string>(); Selection.Select(1); AddItemCommand = ReactiveCommand.Create(() => Items.Add(GenerateItem())); RemoveItemCommand = ReactiveCommand.Create(() => { while (Selection.Count > 0) { Items.Remove(Selection.SelectedItems.First()); } }); SelectRandomItemCommand = ReactiveCommand.Create(() => { var random = new Random(); using (Selection.BatchUpdate()) { Selection.Clear(); Selection.Select(random.Next(Items.Count - 1)); } }); }
public void Reassigning_Model_Tracks_New_Model() { var target = CreateTarget(); var items = target.GetOrCreateItems(); var newModel = new SelectionModel { Source = target.Model.Source }; target.SetModel(newModel); newModel.Select(0); newModel.Select(1); Assert.Equal(new[] { "foo", "bar" }, items); }
public void Handles_Null_Model_Source() { var model = new SelectionModel(); model.Select(1); var target = new SelectedItemsSync(model); var items = target.GetOrCreateItems(); Assert.Empty(items); model.Select(2); model.Source = new[] { "foo", "bar", "baz" }; Assert.Equal(new[] { "bar", "baz" }, items); }
protected override void OnKeyUp(KeyEventArgs e) { if (SelectionModel != null) { if (e.Key == Key.Escape) { SelectionModel.ClearSelection(); } else if (e.Key == Key.Space) { SelectionModel.Select(RepeatedIndex); } 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 (isShiftPressed) { SelectionModel.SelectRangeFromAnchor(RepeatedIndex); } } } base.OnKeyUp(e); }
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { if (SelectionModel != null) { if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift) && !SelectionModel.SingleSelect) { if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { SelectionModel.DeselectRangeFromAnchor(RepeatedIndex); } else { SelectionModel.SelectRangeFromAnchor(RepeatedIndex); } } else if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { if (SelectionModel.IsSelected(RepeatedIndex).Value) { SelectionModel.Deselect(RepeatedIndex); } else { SelectionModel.Select(RepeatedIndex); } } else { SelectionModel.Select(RepeatedIndex); this.Focus(); } } base.OnMouseLeftButtonDown(e); }
public void Reassigning_Model_Tracks_New_Model() { var target = CreateTarget(); var items = target.SelectedItems; var newModel = new SelectionModel <string> { Source = (string[])target.SelectionModel.Source, SingleSelect = false }; target.SelectionModel = newModel; newModel.Select(0); newModel.Select(1); Assert.Equal(new[] { "foo", "bar" }, items); }
public void Handles_Null_Model_Source() { var model = new SelectionModel <string> { SingleSelect = false }; model.Select(1); var target = new SelectedItemsSync(model); var items = target.SelectedItems; Assert.Empty(items); model.Select(2); model.Source = new[] { "foo", "bar", "baz" }; Assert.Equal(new[] { "bar", "baz" }, items); }
public void Assigning_Selection_Should_Raise_SelectionChanged() { var items = new[] { "foo", "bar", "baz" }; var target = new TestSelector { Items = items, Template = Template(), SelectedItem = "bar", }; var raised = 0; target.SelectionChanged += (s, e) => { if (raised == 0) { Assert.Empty(e.AddedItems.Cast <object>()); Assert.Equal(new[] { "bar" }, e.RemovedItems.Cast <object>()); } else { Assert.Equal(new[] { "foo", "baz" }, e.AddedItems.Cast <object>()); Assert.Empty(e.RemovedItems.Cast <object>()); } ++raised; }; target.ApplyTemplate(); target.Presenter.ApplyTemplate(); var selection = new SelectionModel { Source = items }; selection.Select(0); selection.Select(2); target.Selection = selection; Assert.Equal(2, raised); }
public ListBoxPageViewModel() { Items = new ObservableCollection <string>(Enumerable.Range(1, 10000).Select(i => GenerateItem())); Selection = new SelectionModel <string>(); Selection.Select(1); _selectionMode = this.WhenAnyValue( x => x.Multiple, x => x.Toggle, x => x.AlwaysSelected, (m, t, a) => (m ? SelectionMode.Multiple : 0) | (t ? SelectionMode.Toggle : 0) | (a ? SelectionMode.AlwaysSelected : 0)) .ToProperty(this, x => x.SelectionMode); AddItemCommand = ReactiveCommand.Create(() => Items.Add(GenerateItem())); RemoveItemCommand = ReactiveCommand.Create(() => { var items = Selection.SelectedItems.ToList(); foreach (var item in items) { Items.Remove(item); } }); SelectRandomItemCommand = ReactiveCommand.Create(() => { var random = new Random(); using (Selection.BatchUpdate()) { Selection.Clear(); Selection.Select(random.Next(Items.Count - 1)); } }); }
public void Assigning_Single_Selected_Item_To_Selection_Should_Set_SelectedIndex() { var target = new TestSelector { Items = new[] { "foo", "bar" }, Template = Template(), }; target.ApplyTemplate(); target.Presenter.ApplyTemplate(); var selection = new SelectionModel { Source = target.Items }; selection.Select(1); target.Selection = selection; Assert.Equal(1, target.SelectedIndex); Assert.Equal(new[] { "bar" }, target.Selection.SelectedItems); Assert.Equal(new[] { 1 }, SelectedContainers(target)); }
public void Changed(INotifyCollectionChanged sender, NotifyCollectionChangedEventArgs e) { _target.Select(0); }
public void Select() { SelectionModel.Select(GetGroupIndex(), RepeatedIndex); }
public void Execute() { PlaceholderModel model = collectionModel.Get(args.Value); selectionModel.Select(model); }