SortableListView Class

Control to implement the sorting and filtering of a ListView.

Definition

Namespace: Common.Wpf.Controls
Assembly: Common.Wpf.Controls (in Common.Wpf.Controls.dll) Version: 2.0.7
C#
public class SortableListView : ListView
Inheritance
Object    DispatcherObject    DependencyObject    Visual    UIElement    FrameworkElement    Control    ItemsControl    Selector    ListBox    ListView    SortableListView

Remarks

1. Add a namespace attribute to the root element of the markup file it is to be used in:
XAML
xmlns:cc="clr-namespace:Common.Wpf.Controls;assembly=Common.Wpf.Controls"
2. Define the control in XAML setting the DefaultColumn as a one-based column index:
XAML
<cc:SortableListView DefaultColumn="2"... />
3. To implement filtering make sure the FilterPredicate property is set on the control.
XAML
<cc:SortableListView FilterPredicate="{Binding MyFilter}"... />
4. In the ViewModel create the callback function to handle the filtering requirements:
C#
private string _filterText = string.Empty;

public Func<object bool> MyFilter
{
  get
  {
    return (item) =>
    {
      var person = item as Person;
      return person.Name.Contains( _filterText ) ||
        person.Occupation.Contains( _filterText );
    };
  }
}
To perform the filtering make sure the _filterText value is set with the criteria then execute the ApplyFilter() method on the SortableListView control.

Constructors

SortableListViewInitializes a new instance of the SortableListView class

Properties

DefaultColumnGets or sets the default one-based column index.
The default value is 1.
FilterPredicateGets or sets the default filter predicate.

Methods

ApplyFilterApplies the filter predicate to the collection view.
ResetResets the list view.
Sort(GridViewColumnHeader)Sorts the list view based on a grid view column header.
Sort(Int32)Sorts the list view on a one-based column index.

Fields

DefaultColumnPropertyIdentifies the DefaultColumn dependency property.
FilterPredicatePropertyIdentifies the FilterPredicate dependency property.

See Also