xtrareports-17763-desktop-reporting-wpf-reporting-wpf-reporting-document-preview-api-and-customization-provide-custom-editors-for-report-parameters.md
View Example: Reporting for WPF - Custom Editors for Report Parameters
Important
Customization options described in this help topic are available to owners of DevExpress WPF, DXperience, or Universal subscription (subscriptions that include DevExpress WPF UI Controls). The DevExpress Reporting Subscription does not support UI customization in Report Viewer or End-User Report Designer.
Refer to the following help topic for information on subscription options: Installation - Subscriptions that Include Reporting Components.
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);
}
}
}
Imports System.Collections.Generic
Imports System.Windows
Imports DevExpress.Xpf.Printing.Parameters
Imports DevExpress.XtraReports.Parameters.ViewModels
Namespace CustomParameterEditorsWPF
Public Class CustomParameterTemplateSelector
Inherits ParameterTemplateSelector
Private templatesField As Dictionary(Of Object, DataTemplate) = New Dictionary(Of Object, DataTemplate)()
Public ReadOnly Property Templates As Dictionary(Of Object, DataTemplate)
Get
Return templatesField
End Get
End Property
Public Overrides Function SelectTemplate(ByVal item As Object, ByVal container As DependencyObject) As DataTemplate
Dim parameter = TryCast(item, ParameterItemViewModel)
If parameter Is Nothing Then Return Nothing
If parameter.MultiValue Then Return Templates("multiValueTemplate")
Return MyBase.SelectTemplate(item, container)
End Function
End Class
End Namespace
See Also