This is a mirror of official site: http://jasper-net.blogspot.com/

Sorting an Observable Collection using the view model from the MVVM pattern

| Friday, April 8, 2011
Introduction

The purpose of this article is how to allow sorting of controls (e.g. a Listview) that are bound to an ObservableCollection using the MVVM (model, view, view model) pattern and the sorting takes place in the view model.

Background

The background behind this article is I had a requirement to add sorting to a listview that was data bound to an ObservableCollection. The main issue I found was that ObservableCollection is an unordered list and you can't sort it. I struggled to find an article to help achieve this within an MVVM patterned framework, in order that the sorting was done in the view model as opposed to in code behind. This would therefore be more testable and separates my concerns more cleanly.

In order to help anyone else who may have the same problem in the future I thought I'd write up how I achieved this requirement in an MVVM environment

The sample application for this article is a list of people which you will be able to sort by either first name or last name.

So to illustrate we have an unsorted list as below

Read more: Codeproject

Posted via email from Jasper-net

0 comments: