Last active
January 20, 2021 20:31
-
-
Save rdelrosario/04a6a0b46030cf1635090caf0e3918d9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
using System.Collections.ObjectModel; | |
using System.Reactive.Linq; | |
using DynamicData; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
namespace DynamicDataGroupingSample | |
{ | |
public class MainViewModel : IDisposable | |
{ | |
public MainViewModel() | |
{ | |
// Initial data | |
_sourceCache.AddOrUpdate(new List<Restaurant>() | |
{ | |
new Restaurant("Yao","Casual","Asian Fusion","Dominican Republic"), | |
new Restaurant("Chef Pepper","Casual","International","Dominican Republic"), | |
new Restaurant("Bottega Fratelli","Formal","International","Dominican Republic"), | |
new Restaurant("McDonalds","Fast Food","Burgers","United States"), | |
new Restaurant("Burger King","Fast Food","Burgers","United States"), | |
new Restaurant("Sushi Nation","Casual","Sushi","Venezuela"), | |
new Restaurant("Pollo Victorina","Fast Food","Chicken","Dominican Republic"), | |
new Restaurant("Pollo Rey","Fast Food","Chicken","Dominican Republic"), | |
new Restaurant("Asadero Argetino","Formal","Meat","Dominican Republic"), | |
new Restaurant("Hooters","Casual","Wings","United States"), | |
new Restaurant("Andres Carne","Casual","Meat","Colombia"), | |
new Restaurant("La Casita","Casual","Colombian Food","Colombia"), | |
new Restaurant("Cielo","Formal","International","Colombia"), | |
}); | |
_cleanUp = _sourceCache.Connect() | |
.RefCount() | |
.Bind(out _restaurants) | |
.DisposeMany() | |
.Subscribe(); | |
} | |
public ReadOnlyObservableCollection<Restaurant> Restaurants => _restaurants; | |
private SourceCache<Restaurant, string> _sourceCache = new SourceCache<Restaurant, string>(x => x.Id); | |
private readonly ReadOnlyObservableCollection<Restaurant> _restaurants; | |
private readonly IDisposable _cleanUp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment