Skip to content

Instantly share code, notes, and snippets.

@rdelrosario
Created April 28, 2021 15:55
Show Gist options
  • Save rdelrosario/b96d0fdeffa60ffe6097043279e6e389 to your computer and use it in GitHub Desktop.
Save rdelrosario/b96d0fdeffa60ffe6097043279e6e389 to your computer and use it in GitHub Desktop.
namespace DynamicDataGroupingSample
{
public class NotificationConfigurationViewModel : ReactiveObjectEx
{
public NotificationConfigurationViewModel()
{
_notificationConfigurationsSourceCache.AddOrUpdate(new List<NotificationConfiguration>()
{
new NotificationConfiguration("Information", 0,"Development", 0,false, false, true, false),
new NotificationConfiguration("Status Changed", 1,"Administration", 1, false, true, false, false),
new NotificationConfiguration("Error", 3,"Development", 0, false, true, false, false),
new NotificationConfiguration("New Report", 4,"Administration", 1, false, false, false, false),
new NotificationConfiguration("Warning", 1,"Development", 0, false, true, false, false),
new NotificationConfiguration("Security Update", 2, "Administration", 1, false, false, true, true),
new NotificationConfiguration("Verbose", 2, "Development", 0, false, false, false, false),
new NotificationConfiguration("Policy Update", 3, "Administration", 1, false, false, false, false)
});
var notificationConfigurationItemChanges = _notificationConfigurationsSourceCache.Connect()
.RefCount();
notificationConfigurationItemChanges
.Sort(SortExpressionComparer<NotificationConfiguration>.Ascending(a => a.GroupOrder))
.Group(x => x.GroupName)
.Transform(g => new ObservableGroupedCollection<string, NotificationConfiguration, string>(g, null, Observable.Return<IComparer<NotificationConfiguration>>(SortExpressionComparer<NotificationConfiguration>.Ascending(a => a.Order))))
.Bind(out _groups)
.DisposeMany()
.Subscribe()
.DisposeWith(Subscriptions);
}
public ReadOnlyObservableCollection<ObservableGroupedCollection<string, NotificationConfiguration, string>> NotificationGroups => _groups;
private readonly ReadOnlyObservableCollection<ObservableGroupedCollection<string, NotificationConfiguration, string>> _groups;
private SourceCache<NotificationConfiguration, string> _notificationConfigurationsSourceCache = new SourceCache<NotificationConfiguration, string>(x => x.Name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment