New to Telerik UI for WPF? Download free 30-day trial

Data Annotations

By default the RadDataFilter will use each of the fields provided by the underlying business object and will directly use the name of the member. If you have a scenario in which to allow the user to filter the data only by specific members and also to give them user friendly names, you have to use data annotations.

In order to use the data annotations you have to add a reference to the System.ComponentModel.DataAnnotations.dll in your project.

In this case you can use the Display attribute and set the AutoGenerateFilter and ShortName data annotations in it. Here is an example for a Person class, which exposes Name, CompanyName and Title properties. In this case the user is allowed only to filter by the CompanyName and the Title properties. Its display name is also changed to 'Company's Name'.

Example 1: Defining class Person

public class Person 
{ 
    [Display( AutoGenerateFilter = false )] 
    public string Name 
    { 
        get; 
        set; 
    } 
    [Display( ShortName = "Company's Name" )] 
    public string CompanyName 
    { 
        get; 
        set; 
    } 
    public string Title 
    { 
        get; 
        set; 
    } 
} 
Public Class Person 
 <Display(AutoGenerateFilter = False)> _ 
 Public Property Name() As String 
  Get 
   Return m_Name 
  End Get 
  Set 
   m_Name = Value 
  End Set 
 End Property 
 Private m_Name As String 
 <Display(ShortName = "Company's Name")> _ 
 Public Property CompanyName() As String 
  Get 
   Return m_CompanyName 
  End Get 
  Set 
   m_CompanyName = Value 
  End Set 
 End Property 
 Private m_CompanyName As String 
 Public Property Title() As String 
  Get 
   Return m_Title 
  End Get 
  Set 
   m_Title = Value 
  End Set 
 End Property 
 Private m_Title As String 
End Class 

If you filter a collection of Person objects via the RadDataFilter control, in the DropDown for the Data Members you should see the following:

Figure 1: RadDataFilter displaying all the members to filter on. WPF RadDataFilter RadDataFilter displaying all the members to filter on.

You can customize Members shown in the ComboBox with available members to filter on (PART_SimpleFilterMemberComboBox) by specifying whether a property should be displayed or not via BrowsableAttribute.

For example, you can apply the attribute like so:

Example 2: Setting a property to not be displayed

[Browsable(false)] 
[Display(ShortName = "Company's Address")] 
public string CompanyAddress 
{ 
    get; 
    set; 
} 

Figure 2: RadDataFilter displaying the Browsable members.

Rad Data Filter Features Data Annotations 02

See Also

In this article