Skip to main content

Use Favorite Properties in the Report Designer

  • 4 minutes to read

The Report Designer’s Properties Window allows end-users to see only the most frequently used properties.

Overview

The Properties Window displays favorite properties in the Favorites tab.

The Favorites tab includes element properties marked with the Favorite attribute. These properties correspond to those that the element’s smart tag contains. End users can click the Edit Favorite Property List menu item to open the Favorite Properties Editor. This editor lists the current report’s controls. Check/uncheck properties to modify these controls’ favorite property list.

Provide Custom Storage for Favorite Properties

The favorite list is stored in the %localappdata%\Developer Express Inc\XtraReports Suite\ComponentProperties.xml file and is available in all the Report Designer instances.

You can specify any custom file to store favorite properties. Create a FavoritePropertyDirectoryExtension class instance and pass the full file path as a parameter. Use the FavoritePropertyExtension.RegisterExtensionGlobal method to register this instance.

The following code snippet allows you to store the favorite list in the directory with the application’s executable file:

using System.Windows;
using System.IO;
using DevExpress.XtraReports.Extensions;

public partial class App : Application {
    protected override void OnStartup(StartupEventArgs e) {
        string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "FavoriteProperties.xml");
        FavoritePropertyExtension.RegisterExtensionGlobal(new FavoritePropertyDirectoryExtension(path));
        base.OnStartup(e);
    }
}

You can also provide custom storage, such as a database, cloud or any other location. Create a descendant from an abstract FavoritePropertyExtension class and implement its SaveProperties and TryLoadProperties methods.

Specify Your Own Favorite Properties

You can specify your own property set and display it in the Properties window’s favorite list. To do this, create a DescriptionSet class instance and use the SetProperties method. This method accepts the report element name and an array of property names. Then, use the FavoritePropertyDirectoryExtension.SaveProperties method to assign the created instance to the storage extension class.

The example below illustrates how to define favorite properties for the Label control and the report. All other report elements include the predefined favorite list.

using System.Windows;
using System.IO;
using DevExpress.XtraReports.Extensions;
using DevExpress.XtraReports.FavoriteProperties;
using DevExpress.XtraReports.UI;

public partial class App : Application {
    protected override void OnStartup(StartupEventArgs e) {
        SetUpFavoriteProperties();
        base.OnStartup(e);
    }

    static void SetUpFavoriteProperties() {
        string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "FavoriteProperties.xml");
        FavoritePropertyDirectoryExtension extension = new FavoritePropertyDirectoryExtension(path);
        DescriptionSet set;
        if (!extension.TryLoadProperties(out set)) {
            set = new DescriptionSet();
            set.SetProperties(typeof(XRLabel).Name, new string[] { "BackColor", "ForeColor" });
            set.SetProperties(typeof(XtraReport).Name, new string[] { "DataSource", "DataMember" });
            extension.SaveProperties(set);
        }
        FavoritePropertyExtension.RegisterExtensionGlobal(extension);
    }
}

The following image shows the result.

Customize Predefined Favorite Properties

Use the static FavoritePropertyExtension.GetFavoriteProperties method to get the predefined set of favorite properties for a specific report element type. You can customize the obtained array as required (delete and/or add new properties).

Create a DescriptionSet class instance and use the SetProperties method to specify your custom set of favorite properties. Use the FavoritePropertyDirectoryExtension.SaveProperties method to assign this class instance to the storage extension class.

The example below allows you to customize predefined favorites for a report, in particular, remove the FilterString property and add the CalculatedFields property.

using System;
using System.Windows;
using System.Collections.Generic;
using System.IO;
using DevExpress.XtraReports.Extensions;
using DevExpress.XtraReports.FavoriteProperties;
using DevExpress.XtraReports.UI;

public partial class App : Application {
    protected override void OnStartup(StartupEventArgs e) {
        SetUpFavoriteProperties();
        base.OnStartup(e);
    }

    static void SetUpFavoriteProperties() {
        string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FavoriteProperties.xml");
        FavoritePropertyDirectoryExtension extension = new FavoritePropertyDirectoryExtension(path);
        DescriptionSet set;
        if (!extension.TryLoadProperties(out set)) {           
            List<string> favorites = new List<string>(FavoritePropertyExtension.GetFavoriteProperties(typeof(XtraReport)));
            favorites.Remove("FilterString");
            favorites.Add("CalculatedFields");
            set = new DescriptionSet();
            set.SetProperties(typeof(XtraReport).Name, favorites.ToArray());
            extension.SaveProperties(set);
        }
        FavoritePropertyExtension.RegisterExtensionGlobal(extension);
    }
}

The following image illustrates the resulting favorite list: