Use Favorite Properties in the Report Designer

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

Overview

The Properties panel displays favorite control properties if an end-user selected the Show Favorite Properties menu item.

This adds a star to the Properties button's icon. The favorite list includes element properties marked with the Favorite attribute. These properties correspond to those that the corresponding element's smart tag contains.

You can initially display the favorite list in the Report Designer's Properties panel as shown below.

<Window ...
        xmlns:dxrud="http://schemas.devexpress.com/winfx/2008/xaml/reports/userdesigner">

    <dxrud:ReportDesigner PropertyGridOptions="{dxrud:PropertyGridOptions ShowFavoriteProperties=True}"/>
</Window>

End-users can click the Edit Favorite Properties menu item to open the Favorite Properties Editor and set up their favorite properties. This editor lists the current report's report controls. The favorite list includes a property if the corresponding check box is enabled.

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 Property Grid'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: