Created
August 1, 2014 18:06
-
-
Save moswald/45554c8eb0967f0d5d47 to your computer and use it in GitHub Desktop.
How to deal with multiple selections on a ListView control (WinRT) with RxUI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// in the View constructor | |
this.WhenActivated(d => | |
{ | |
d(MyListView.Events().SelectionChanged.Subscribe(args => | |
{ | |
foreach (var item in args.AddedItems.Cast<MyModelType>()) | |
{ | |
item.IsSelected = true; | |
} | |
foreach (var item in args.RemovedItems.Cast<MyModelType>()) | |
{ | |
item.IsSelected = false; | |
} | |
}); | |
}); | |
// | |
// in the ViewModel constructor | |
Models = new ReactiveList<MyModelType>(/* initialize... */); | |
SelectedModels = Models.CreateDerivedCollection(x => x, model => model.IsSelected); | |
// | |
// definition of the model object for completeness | |
public class MyModelType : ReactiveObject | |
{ | |
private bool _isSelected; | |
public bool IsSelected | |
{ | |
get { return _isSelected; } | |
set { this.RaiseAndSetIfChanged(ref _isSelected, value); } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment