public SelectManyDemoVm() { Items = new ObservableCollection <ItemVm>().AllDisposedBy(this); SelectedIds = new ObservableCollection <string> { "2", "5", "8", "1111", "11115", "22229", "StamItem" }; Initialize(); SelectionCommand = MvvmRx.CreateCommand <IEnumerable <String> >(this); RandomFiveCommand = MvvmRx.CreateCommand(this); RemoveSelected = MvvmRx.CreateCommand <IEnumerable>(this); ResetCommand = MvvmRx.CreateCommand(this); ClearCommand = MvvmRx.CreateCommand(this); SelectionCommand.Select(ienum => ienum.ToObservableCollection()).ApplyOnProperty(this, x => x.SelectedIds); RandomFiveCommand.Subscribe(_ => { var rnd = new Random(); var items = Enumerable.Range(0, 5).Select(__ => Items[rnd.Next(Items.Count)].Uid); SelectedIds.AddRange(items); }).DisposedBy(this); RemoveSelected.Subscribe(x => { foreach (var item in x.OfType <string>().ToArray()) { SelectedIds.Remove(item); } }).DisposedBy(this); ResetCommand.Subscribe(_ => { var rnd = new Random(); var ids = Items.Select(x => x.Uid).Where(x => rnd.Next(40) < 2).ToObservableCollection(); SelectedIds = ids; }).DisposedBy(this); ClearCommand.Subscribe(_ => { Items.Clear(); }).DisposedBy(this); }
private void NotifyCanExecuteChanged() { SelectAll.NotifyCanExecuteChanged(); RemoveSelected.NotifyCanExecuteChanged(); ClearSelection.NotifyCanExecuteChanged(); }