|
@@ -10,15 +10,30 @@ namespace ControlCatalog.ViewModels
|
|
|
{
|
|
|
public class ListBoxPageViewModel : ReactiveObject
|
|
|
{
|
|
|
+ private bool _multiple;
|
|
|
+ private bool _toggle;
|
|
|
+ private bool _alwaysSelected;
|
|
|
+ private bool _autoScrollToSelectedItem = true;
|
|
|
private int _counter;
|
|
|
- private SelectionMode _selectionMode;
|
|
|
+ private ObservableAsPropertyHelper<SelectionMode> _selectionMode;
|
|
|
|
|
|
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(() =>
|
|
@@ -42,25 +57,37 @@ namespace ControlCatalog.ViewModels
|
|
|
}
|
|
|
|
|
|
public ObservableCollection<string> Items { get; }
|
|
|
-
|
|
|
public SelectionModel<string> Selection { get; }
|
|
|
+ public SelectionMode SelectionMode => _selectionMode.Value;
|
|
|
|
|
|
- public ReactiveCommand<Unit, Unit> AddItemCommand { get; }
|
|
|
+ public bool Multiple
|
|
|
+ {
|
|
|
+ get => _multiple;
|
|
|
+ set => this.RaiseAndSetIfChanged(ref _multiple, value);
|
|
|
+ }
|
|
|
|
|
|
- public ReactiveCommand<Unit, Unit> RemoveItemCommand { get; }
|
|
|
+ public bool Toggle
|
|
|
+ {
|
|
|
+ get => _toggle;
|
|
|
+ set => this.RaiseAndSetIfChanged(ref _toggle, value);
|
|
|
+ }
|
|
|
|
|
|
- public ReactiveCommand<Unit, Unit> SelectRandomItemCommand { get; }
|
|
|
+ public bool AlwaysSelected
|
|
|
+ {
|
|
|
+ get => _alwaysSelected;
|
|
|
+ set => this.RaiseAndSetIfChanged(ref _alwaysSelected, value);
|
|
|
+ }
|
|
|
|
|
|
- public SelectionMode SelectionMode
|
|
|
+ public bool AutoScrollToSelectedItem
|
|
|
{
|
|
|
- get => _selectionMode;
|
|
|
- set
|
|
|
- {
|
|
|
- Selection.Clear();
|
|
|
- this.RaiseAndSetIfChanged(ref _selectionMode, value);
|
|
|
- }
|
|
|
+ get => _autoScrollToSelectedItem;
|
|
|
+ set => this.RaiseAndSetIfChanged(ref _autoScrollToSelectedItem, value);
|
|
|
}
|
|
|
|
|
|
+ public ReactiveCommand<Unit, Unit> AddItemCommand { get; }
|
|
|
+ public ReactiveCommand<Unit, Unit> RemoveItemCommand { get; }
|
|
|
+ public ReactiveCommand<Unit, Unit> SelectRandomItemCommand { get; }
|
|
|
+
|
|
|
private string GenerateItem() => $"Item {_counter++.ToString()}";
|
|
|
}
|
|
|
}
|