Skip to content

Instantly share code, notes, and snippets.

@julesx
Created Apr 17, 2015
Embed
What would you like to do?
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