Show Me |
---|
在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E2856。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。 |
本示例演示了如何为显示在报表打印预览用户界面中的 参数 提供自定义编辑器。
要这样做,则在 XtraReportPreviewModel.CustomizeParameterEditors 事件处理程序中重写已有的编辑器,并且把它的 CustomizeParameterEditorsEventArgs.BoundDataMember 属性指定为与参数相关联的数据成员。
如有必要,也可以定义 CustomizeParameterEditorsEventArgs.BoundDataConverter (一个实现了 System.Windows.Data.IValueConverter 接口的转换器) 和 CustomizeParameterEditorsEventArgs.BoundDataConverterParameter (一个可以被转换器的方法使用的参数)。
Xaml | 复制代码 |
---|---|
(MainPage.xaml) <UserControl x:Class="CustomizeParameterEditorSample.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxp="http://schemas.devexpress.com/winfx/2008/xaml/printing"> <dxp:DocumentPreview x:Name="preview" /> </UserControl> |
C# | 复制代码 |
---|---|
(MainPage.xaml.cs) using System.Collections.ObjectModel; using System.Windows.Controls; using DevExpress.Xpf.Editors; using DevExpress.Xpf.Printing; using DevExpress.Xpf.Core; // ... namespace CustomizeParameterEditorSample { public partial class MainPage : UserControl { ReadOnlyCollection<string> conditions = new ReadOnlyCollection<string>(new string[] { "Quantity more than 30", "Quantity more than 60", "Unit price more than 40", "Unit price more than 60", "Discount more than 5", "Discount more than 15", "Extended price more than 1000", "Extended price more than 1500" }); ReadOnlyCollection<string> styles = new ReadOnlyCollection<string>(new string[] { "Tahoma Bold", "Dark Red", "Light Red", "Dark Blue", "Light Blue", "Dark Green", "Light Green" }); public MainPage() { ThemeManager.ApplicationThemeName = "Office2007Black"; InitializeComponent(); ReportPreviewModel model = new ReportPreviewModel("../ReportService.svc"); model.ReportTypeName = "CustomizeParameterEditorSample.Web.OrdersReport"; model.CustomizeParameterEditors += model_CustomizeParameterEditors; preview.Model = model; model.CreateDocument(); } void model_CustomizeParameterEditors(object sender, CustomizeParameterEditorsEventArgs e) { if(e.Parameter.Name == "ConditionIndexParameter") { e.Editor = new ComboBoxEdit() { IsTextEditable = false, ItemsSource = conditions }; e.BoundDataMember = "SelectedIndex"; } if(e.Parameter.Name == "StyleIndexParameter") { e.Editor = new ComboBoxEdit() { IsTextEditable = false, ItemsSource = styles }; e.BoundDataMember = "SelectedIndex"; } } } } |
Visual Basic | 复制代码 |
---|---|
(MainPage.xaml.vb) Imports System.Collections.ObjectModel Imports System.Windows.Controls Imports DevExpress.Xpf.Editors Imports DevExpress.Xpf.Printing Imports DevExpress.Xpf.Core ' ... Namespace CustomizeParameterEditorSample Partial Public Class MainPage Inherits UserControl Private conditions As New ReadOnlyCollection(Of String)(New String() { "Quantity more than 30", "Quantity more than 60", "Unit price more than 40", "Unit price more than 60", "Discount more than 5", "Discount more than 15", "Extended price more than 1000", "Extended price more than 1500"}) Private styles As New ReadOnlyCollection(Of String)(New String() { "Tahoma Bold", "Dark Red", "Light Red", "Dark Blue", "Light Blue", "Dark Green", "Light Green"}) Public Sub New() ThemeManager.ApplicationThemeName = "Office2007Black" InitializeComponent() Dim model As New ReportPreviewModel("../ReportService.svc") model.ReportTypeName = "CustomizeParameterEditorSample.Web.OrdersReport" AddHandler model.CustomizeParameterEditors, AddressOf model_CustomizeParameterEditors preview.Model = model model.CreateDocument() End Sub Private Sub model_CustomizeParameterEditors(ByVal sender As Object, _ ByVal e As CustomizeParameterEditorsEventArgs) If e.Parameter.Name = "ConditionIndexParameter" Then e.Editor = _ New ComboBoxEdit() With {.IsTextEditable = False, .ItemsSource = conditions} e.BoundDataMember = "SelectedIndex" End If If e.Parameter.Name = "StyleIndexParameter" Then e.Editor = _ New ComboBoxEdit() With {.IsTextEditable = False, .ItemsSource = styles} e.BoundDataMember = "SelectedIndex" End If End Sub End Class End Namespace |
在下面的插图中显示了结果。