Skip to main content
.NET Framework 4.5.2+

Use Criteria Property Editors

  • 7 minutes to read

This topic details the specifics of using Criteria Property Editors in an XAF application. The topic demonstrates an application that allows users to design and save filtering criteria at runtime.


A complete sample project is available in the DevExpress Code Examples database at

To create the sample application, do the following:

  1. Define business classes whose List Views should be filtered.
  2. Define the FilteringCriterion business class that represents filtering criteria for the Product‘s List View.
  3. Create a custom View Controller that contains an Action used to filter the List View.

To begin building the sample application, create a new XAF application solution named HowToUseCriteriaPropertyEditors using the DevExpress v23.1 XAF Template Gallery Template Gallery.Built-in Visual Studio Templates.

Step 1 - Add the Product and Person Business Classes

Right-click the HowToUseCriteriaPropertyEditors.Module project, and choose Add DevExpress Item | New Item… to invoke Template Gallery. Then select the XAF Business Object | XPO Business Object project item, name it Product, and press Add Item. You will get an automatically generated code file with a single class declaration. Replace the automatically generated class declaration with the following code, defining a class with four persistent properties of different types:

using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl.EF;

[DefaultClassOptions, ImageName("BO_Product")]
public class Product : BaseObject {
    public virtual string Name { get; set; }
    public virtual double Price { get; set; }
    public virtual int Quantity { get; set; }
    public virtual Person Manager { get; set; }

public class Person : BaseObject {
    public virtual string FirstName { get; set; }
    public virtual string LastName { get; set; }
    // ...

// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.

The Manager reference property is of the Person type. Add a Person item to the ShowNavigationItem and to the New action, via the Model Editor (see Add an Item to the Navigation Control).

Step 2 - Define the FilteringCriterion Business Class

Add the Domain Object named FilteringCriterion to the HowToUseCriteriaPropertyEditors.Module project, and replace the automatically generated class declaration with the following code:

using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Editors;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl.EF;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using System.ComponentModel;

public class ApplicationDbContext : DbContext {
    // ...
    public DbSet<FilteringCriterion> FilteringCriterions { get; set;}
    // ...
    protected override void OnModelCreating(ModelBuilder modelBuilder) {
        // ...
            .Property(t => t.ObjectType)
            .HasConversion(new TypeToStringConverter());

public class TypeToStringConverter : ValueConverter<Type, string> {
    public TypeToStringConverter() : base(
            v => v.FullName,
            v => ReflectionHelper.FindType(v)) { }

public class FilteringCriterion : BaseObject {
    public virtual string Description { get; set; }
    public virtual Type ObjectType { get; set; }
    public virtual string Criterion { get; set; }

// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.

Objects of this class represent filtering criteria. The Description field contains the text that describes a criterion. These descriptions will be used to fill a drop-down list of possible filters. The Criterion property holds a criterion. To use the built-in XAF Criteria Property Editors, the property that holds a criterion must have the CriteriaOptionsAttribute applied. The attribute’s parameter is the name of an additional Type property, which specifies the objects’ type used in the construction of the criterion. In this sample, it is the ObjectType property. Additionally, the EditorAliasAttribute with the PopupCriteriaPropertyEditor alias is applied to the Criterion property. This attribute changes the default Property Editor for the property:

  • PopupCriteriaPropertyEditor is used in Windows Forms applications
  • ASPxPopupCriteriaPropertyEditor is used in ASP.NET Web Forms applications
  • PopupFilterPropertyEditor is used in ASP.NET Core Blazor applications

Step 3 - Create a Custom List View Controller

Add the following CriteriaController class to the HowToUseCriteriaPropertyEditors.Module project.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Editors;
using DevExpress.Data.Filtering;
using DevExpress.ExpressApp.Templates;
// ...
public class CriteriaController : ObjectViewController {
    private SingleChoiceAction filteringCriterionAction;
    public CriteriaController() {
        filteringCriterionAction = new SingleChoiceAction(
            this, "FilteringCriterion", PredefinedCategory.Filters);
        filteringCriterionAction.Execute += this.FilteringCriterionAction_Execute;
        TargetViewType = ViewType.ListView;
    protected override void OnActivated() {
        foreach (FilteringCriterion criterion in ObjectSpace.GetObjects<FilteringCriterion>())
            if (criterion.ObjectType.IsAssignableFrom(View.ObjectTypeInfo.Type)) {
                    new ChoiceActionItem(criterion.Description, criterion.Criterion));
        if (filteringCriterionAction.Items.Count > 0)
            filteringCriterionAction.Items.Add(new ChoiceActionItem("All", null));
    private void FilteringCriterionAction_Execute(
        object sender, SingleChoiceActionExecuteEventArgs e) {
        ((ListView)View).CollectionSource.Criteria[nameof(CriteriaController)] =
            e.SelectedChoiceActionItem.Data as string, View.ObjectTypeInfo.Type, ObjectSpace);

This Controller adds the FilteringCriterion SingleChoiceAction and populates the Action’s dropdown list with all the existing FilterCriterion objects whose ObjectType matches the type of objects displayed in the current List View.

The FilteringCriterion Action applies the criterion selected in the dropdown list to the List View. Note that to convert the Criterion property’s value of a FilterCriterion object to the DevExpress.Data.Filtering.CriteriaOperator object, you need to call the static CriteriaEditorHelper.GetCriteriaOperator method. This method takes three parameters. The string parameter represents the criterion to be converted. The Type parameter specifies the object type for which the criterion is constructed. The ObjectSpace parameter specifies any IObjectSpace that contains objects of the specified type.


You should not use the CriteriaOperator.Parse method in this scenario. Criteria Property Editors can generate Criteria Strings containing Object Parameters, which are specific to XAF and cannot be parsed by CriteriaOperator.Parse.

Now you can run the Windows Forms, ASP.NET Web Forms, or ASP.NET Core Blazor application, create several Person, Product and FilterCriteria objects, and then try the FilteringCriterion action.


The Criteria Property Editors are also demonstrated in the Property Editors | Criteria Properties section in the Feature Center demo installed with XAF. The default location of the application is %PUBLIC%\Documents\DevExpress Demos 23.1\Components\XAF\FeatureCenter.NETFramework.XPO.

See Also