RadControls version |
RadControls for WPF Q2 2010 SP1
|
.NET version |
4.0
|
Visual Studio version |
2010
|
programming language |
c#
|
browser support |
all browsers supported by RadControls
|
PROJECT DESCRIPTION
I created some extension methods and one helper class for the RadDataFilter WPF-Control. The main goals of the project are:
- Store and reload current filters as XML
- Basic support for enums
- Basic support for object graphs with dot notation
I think that the usability of the RadDataFilter is extremely high. But for my specific needs I miss some features. In my use case I have business objects that are linked in an object graph (e.g. Customer.Address.Street). I want to implement a rule engine that selects specific business objects with filters that are defined with RadDataFilter control. But for that it must be possible to store and reload filter settings and
evaluate filters without the RadDataFilter control in a ViewModel.
If you use RadDataFilter in "unbound" mode you can define custom ItemPropertyInfos. So it is possible to use dot notation for a complete object graph. But then you don't have binding. The UnboundRadDataFilterHelper class fits this requirement. It is a DependencyObject wich properties are bindable in XAML.
Further more I have some enum properties in my business objects. I implemented automatic filling of a RadComboBox as editor for enums in RadDataFilter.
The UnboundRadDataFilterHelper is a generic class which expects a RadDataFilter instance as constructor parameter. The generic type parameter represents the type of the filtered instances. The helper class has a
Source and a FilteredSource property like the RadDataFilter control itself. But these properties can be used in "unbound" mode, too. The
FilterXml property represents the current filter settings as xml. This property is read- and writeable.
The Extensions class exposes the following extension methods:
/// <summary>
/// Serialize CompositeFilterDescriptorCollection to XML
/// </summary>
/// <param name="collection">CompositeFilterDescriptorCollection</param>
/// <typeparam name="T">The type that the filters are based on</typeparam>
/// <returns>The XML</returns>
public
static
XDocument GetXDocument<T>(
this
CompositeFilterDescriptorCollection collection)
{ ... }
/// <summary>
/// Serialize IFilterDescriptor
/// </summary>
/// <param name="filter">FilterDescriptor</param>
/// <returns>The XML</returns>
public
static
XElement GetXElement(
this
IFilterDescriptor filter)
{ ... }
/// <summary>
/// Get FilterDescriptorCollection from XML
/// </summary>
/// <param name="document">XML document</param>
/// <returns>CompositeFilterDescriptorCollection</returns>
public
static
CompositeFilterDescriptorCollection GetFilterDescriptorCollection(
this
XDocument document)
{ ... }
/// <summary>
/// Get IFilterDescriptor from XML
/// </summary>
/// <param name="element">XML element</param>
/// <returns>IFilterDescriptor instance</returns>
public
static
IFilterDescriptor GetIFilterDescriptor(
this
XElement element)
{ ... }
/// <summary>
/// Set FilterDescriptors in RadDataFilter fom XML document
/// </summary>
/// <param name="radDataFilter">RadDataFilter instance</param>
/// <param name="document">XML document</param>
public
static
void
SetFilterDescriptors(
this
RadDataFilter radDataFilter, XDocument document)
{ ... }
/// <summary>
/// Get filter method from FilterDescriptor
/// </summary>
/// <typeparam name="T">The type that the filter is based on</typeparam>
/// <param name="filterDescriptor">FilterDescriptor</param>
/// <returns>Dynamic compiled filter method</returns>
public
static
Func<T,
bool
> GetFilter<T>(
this
IFilterDescriptor filterDescriptor)
{ ... }
/// <summary>
/// Does the filter match?
/// </summary>
/// <typeparam name="T">The type that the filter is based on</typeparam>
/// <param name="item">Filtered item of type T</param>
/// <param name="filterDescriptor">FilterDescriptor</param>
/// <returns>Does the filter match?</returns>
public
static
bool
MatchesFilter<T>(
this
T item, IFilterDescriptor filterDescriptor)
{ ... }
/// <summary>
/// Filter IEnumerable of type T
/// </summary>
/// <typeparam name="T">The type the filter is based on</typeparam>
/// <param name="items">Items of type T</param>
/// <param name="filterDescriptor">FilterDescriptor</param>
/// <returns>Get the matched items</returns>
public
static
IEnumerable<T> Filter<T>(
this
IEnumerable<T> items, IFilterDescriptor filterDescriptor)
{ ... }
I hope it is clear what I tried to say ;-) Any comments are welcome.
Best regards,
Oliver