SortableListView Class
Control to implement the sorting and filtering of a ListView.
1. Add a namespace attribute to the root element of the markup file it is to be used in:
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:
<cc:SortableListView DefaultColumn="2"... />
3. To implement filtering make sure the
FilterPredicate property is set on the control.
<cc:SortableListView FilterPredicate="{Binding MyFilter}"... />
4. In the
ViewModel create the callback function to handle the filtering requirements:
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.
DefaultColumn | Gets or sets the default one-based column index.
The default value is 1. |
FilterPredicate | Gets or sets the default filter predicate. |