Skip to content

Instantly share code, notes, and snippets.

@RolandPheasant
Last active March 20, 2017 21:44
Show Gist options
  • Save RolandPheasant/93e73b0d2ba2977e49d5c651fb845ee7 to your computer and use it in GitHub Desktop.
Save RolandPheasant/93e73b0d2ba2977e49d5c651fb845ee7 to your computer and use it in GitHub Desktop.
Transform many example (using observable collection)
/*
* This example works with observable collection. When using reactive list add package DynamicData.ReactiveUI (Use dynamic data v4x - later version are based off rx3x with rxui does not support)
* Normally with dd you would manage a collection independent of binding i.e. use SourceCache<T,K> or SourceList<T>, shape the collection and uae the Bind() operator to maintain an observable collection. See github homepage for links and examples
*/
ObservableCollection<A> listOfA = new ObservableCollection<A>();
//create a collection to bind to
ReadOnlyObservableCollection<B> binding;
// OPTION 1: if listb is IEnumerable<B>
var loader = listOfA.ToObservableChangeSet() //change collection into an observable changeset
.TransformMany(a => a.ListOfB) //select many items
//maybe sort first + push onto UI thread
.Bind(out binding)
.Subscribe();
// OPTION 2: if listb is ObservableCollection<B>
var loader = listOfA.ToObservableChangeSet()
.TransformMany(a => a.ListOfB.ToObservableChangeSet())
.Or() //apply a logic all to all of the inner collections
//maybe sort first + push onto UI thread
.Bind(out binding)
.Subscribe();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment