Skip to content

Instantly share code, notes, and snippets.

@moswald
Created August 1, 2014 18:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save moswald/45554c8eb0967f0d5d47 to your computer and use it in GitHub Desktop.
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
//
// 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