ExpressionBinding Class
Provides functionality to expression bindings.
Namespace: DevExpress.XtraReports.UI
Assembly: DevExpress.XtraReports.v24.2.dll
NuGet Package: DevExpress.Reporting.Core
Declaration
Remarks
A collection of ExpressionBinding objects is returned by the XRControl.ExpressionBindings property.
An expression enables you to specify a property value for a control or a parameter.
To create an expression binding for a report control, create an ExpressionBinding
object, specify its properties, and add the ExpressionBinding
object to the XRControl.ExpressionBindings collection.
The ExpressionBinding
constructor needs the following arguments:
- EventName
- The name of the event whose handler evaluates the expression. Typically you should set this property to the “BeforePrint” (the BeforePrint event) or “PrintOnPage” (the PrintOnPage event) string. If you omit this property, the expression is evaluated in the BeforePrint event. You can use the
[Arguments.PageIndex]
value to get the current page index in the expression evaluated in the PrintOnPage event. - PropertyName
- The property to which the expression applies.
- Expression
- A binding expression that is parsed and processed to specify a control or parameter’s property value.
The following code snippet specifies an expression for a control’s property:
using DevExpress.XtraReports.UI;
public partial class XtraReport1 : DevExpress.XtraReports.UI.XtraReport {
public XtraReport1() {
InitializeComponent();
XRLabel label = new XRLabel();
this.Report.Bands[BandKind.Detail].Controls.Add(label);
label.LeftF = 100;
label.TopF = 100;
// Specify an expression that sets the label's Text to the current date. The expression is rendered within the BeforePrint event.
label.ExpressionBindings.Add(new ExpressionBinding("Text", "TODAY()"));
// Specify an expression that makes the text bold on the first page.
label.ExpressionBindings.Add(new ExpressionBinding("PrintOnPage", "Font.Bold", "Iif([Arguments.PageIndex] == 0, true, false)"));
}
}
The following code specifies a custom expression for the label’s XRControl.Text property. The code assumes that the report is bound to a data source with UnitPrice
and UnitsInStock
fields.
using DevExpress.XtraReports.UI;
public XtraReport1() {
// ...
ExpressionBinding expressionBinding = new ExpressionBinding("BeforePrint", "Text", "[UnitPrice]*[UnitsInStock]");
xrLabel1.ExpressionBindings.Add(expressionBinding);
}
Review the following topic for more information: Data Binding Modes.