Skip to main content

Custom Editors for Report Parameters (WPF)

  • 2 minutes to read

View Example: Reporting for WPF - Custom Editors for Report Parameters

This example demonstrates how you can provide custom editors for report parameters of arbitrary types. In particular, it shows how to utilize a custom ComboBoxEdit as an editor for a multi-value report parameter.

To provide the described functionality, implement a custom parameter template selector and assign it to the ParametersPanel.ParameterTemplateSelector property of the DocumentPreviewControl‘s ParametersPanel. In this example, the custom parameters template selector extends the base ParameterTemplateSelector class with the capability to provide a custom editor template for each parameter, whose Parameter.MultiValue property is set to true. The custom editor template is declared in XAML.

<Window.Resources>
    <local:CustomParameterTemplateSelector x:Key="parameterTemplateSelector">
        <local:CustomParameterTemplateSelector.Templates>
            <DataTemplate x:Key="multiValueTemplate">
                <dxpp:ParameterLineLayout>
                    <dxe:ComboBoxEdit Grid.Column="1" MinWidth="70" ShowCustomItems="True"
                        IncrementalFiltering="False" AutoComplete="True" ImmediatePopup="True"
                        ItemsSource="{Binding LookUpValues}" DisplayMember="RealDescription" ValueMember="Value" MaxHeight="90" FocusPopupOnOpen="False">
                        <mvvm:Interaction.Behaviors>
                            <dxpp:MutliValueBindingProvider SourceType="{Binding Type}" />
                            <dxpp:ShowPopupBehavior />
                        </mvvm:Interaction.Behaviors>
                        <dxe:ComboBoxEdit.StyleSettings>
                            <dxe:CheckedTokenComboBoxStyleSettings AllowEditTokens="False" EnableTokenWrapping="True" ShowTokenButtons="True" NewTokenPosition="Far" />
                        </dxe:ComboBoxEdit.StyleSettings>
                    </dxe:ComboBoxEdit>
                </dxpp:ParameterLineLayout>
            </DataTemplate>
        </local:CustomParameterTemplateSelector.Templates>
    </local:CustomParameterTemplateSelector>
    <Style TargetType="{x:Type dxpp:ParametersPanel}">
        <Setter Property="ParameterTemplateSelector" Value="{StaticResource parameterTemplateSelector}" />
    </Style>
</Window.Resources>
using System.Collections.Generic;
using System.Windows;
using DevExpress.Xpf.Printing.Parameters;
using DevExpress.XtraReports.Parameters.ViewModels;

namespace CustomParameterEditorsWPF
{
    public class CustomParameterTemplateSelector : ParameterTemplateSelector {
        Dictionary<object, DataTemplate> templates = new Dictionary<object, DataTemplate>();
        public Dictionary<object, DataTemplate> Templates { get { return templates; } }

        public override DataTemplate SelectTemplate(object item, DependencyObject container) {
            var parameter = item as ParameterItemViewModel;
            if(parameter == null)
                return null;
            if(parameter.MultiValue)
                return Templates["multiValueTemplate"];
            return base.SelectTemplate(item, container);
        }
    }
}
See Also