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.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using DevExpress.Xpf.Printing.Parameters;
using DevExpress.Xpf.Printing.Parameters.Models;
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 ParameterModel;
if(parameter == null)
return null;
if(parameter.MultiValue)
return Templates["multiValueTemplate"];
return base.SelectTemplate(item, container);
}
}
}
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:dxp="http://schemas.devexpress.com/winfx/2008/xaml/printing"
xmlns:dxpp="clr-namespace:DevExpress.Xpf.Printing.Parameters;assembly=DevExpress.Xpf.Printing.v15.2"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:local="clr-namespace:CustomParameterEditorsWPF"
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars" xmlns:System="clr-namespace:System;assembly=mscorlib" x:Class="CustomParameterEditorsWPF.MainWindow"
Title="MainWindow" Height="720" Width="1280">
<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>
<dxp:DocumentPreviewControl x:Name="preview" />
</Window>
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports DevExpress.Xpf.Printing.Parameters
Imports DevExpress.Xpf.Printing.Parameters.Models
Namespace CustomParameterEditorsWPF
Public Class CustomParameterTemplateSelector
Inherits ParameterTemplateSelector
Private templates_Renamed As New Dictionary(Of Object, DataTemplate)()
Public ReadOnly Property Templates() As Dictionary(Of Object, DataTemplate)
Get
Return templates_Renamed
End Get
End Property
Public Overrides Function SelectTemplate(ByVal item As Object, ByVal container As DependencyObject) As DataTemplate
Dim parameter = TryCast(item, ParameterModel)
If parameter Is Nothing Then
Return Nothing
End If
If parameter.MultiValue Then
Return Templates("multiValueTemplate")
End If
Return MyBase.SelectTemplate(item, container)
End Function
End Class
End Namespace
See Also