Skip to content

Instantly share code, notes, and snippets.

@julesx
Created April 17, 2015 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julesx/acd0e1c03f9d90bd6094 to your computer and use it in GitHub Desktop.
Save julesx/acd0e1c03f9d90bd6094 to your computer and use it in GitHub Desktop.
using System.Windows;
namespace PageableListBox
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = new MainWindowVm();
}
}
}
<Window x:Class="PageableListBox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<ListBox ItemsSource="{Binding Items}" />
</Window>
using System;
using System.Reactive.Linq;
using DynamicData;
using DynamicData.Binding;
using DynamicData.Controllers;
namespace PageableListBox
{
public class MainWindowVm
{
public ObservableCollectionExtended<MyVm> Items { get; set; }
public MainWindowVm()
{
var myCache = new SourceCache<MyVm, string>(myobject => myobject.Id);
//this is an extension of observable collection optimised for dynamic data
Items = new ObservableCollectionExtended<MyVm>();
//these controllers enable dynamically changing filter, sort and page
var pageController = new PageController();
var filterController = new FilterController<MyVm>();
var sortController = new SortController<MyVm>(SortExpressionComparer<MyVm>.Ascending(t => t.Id));
var mySubscription = myCache.Connect()
.Filter(filterController)
.Sort(sortController)
.Page(pageController)
.ObserveOnDispatcher()
.Bind(Items)
.Subscribe();
myCache.AddOrUpdate(new MyVm("1"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment