Back to Devexpress

XtraReport.WatermarkId Property

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xtrareport-932cb53e.md

latest5.9 KB
Original Source

XtraReport.WatermarkId Property

Bindable. Specifies the unique identifier of a watermark to be displayed in a report.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
[DefaultValue(null)]
[SRCategory(ReportStringId.CatAppearance)]
public string WatermarkId { get; set; }
vb
<SRCategory(ReportStringId.CatAppearance)>
<DefaultValue(Nothing)>
Public Property WatermarkId As String

Property Value

TypeDefaultDescription
Stringnull

A watermark unique identifier.

|

Remarks

WatermarkId allows you to specify a watermark from the collection to display in the report. This property has a priority over the watermark’s PageRange property.

The following code snippet adds two watermarks in WatermarkCollection and displays the second watermark in a report:

csharp
using DevExpress.Drawing;
using DevExpress.XtraPrinting.Drawing;
using DevExpress.XtraReports.UI;
// ...
XtraReportCategories report = new XtraReportCategories();
  report.Watermarks.Add(CreateTextWatermark("First Watermark","Watermark1"));
  report.Watermarks.Add(CreateTextWatermark("Second Watermark", "Watermark2"));
  report.WatermarkId = "Watermark2";
  report.ShowRibbonPreviewDialog();
  // ...

private XRWatermark CreateTextWatermark(string text, string id) {
XRWatermark textWatermark = new XRWatermark();
textWatermark.Text = text;
textWatermark.Id = id; 
textWatermark.TextDirection = DirectionMode.ForwardDiagonal;
textWatermark.Font = new DXFont("Verdana", 36);
textWatermark.TextPosition = WatermarkPosition.InFront;
textWatermark.ForeColor = Color.Red;
return textWatermark;
}
vb
Imports DevExpress.Drawing
Imports DevExpress.XtraPrinting.Drawing
Imports DevExpress.XtraReports.UI
' ...
Partial Public Class Form1
    Inherits Form

        Public Sub New()
            InitializeComponent()
            Dim report As New XtraReportCategories()
                report.Watermarks.Add(CreateTextWatermark("First Watermark","Watermark1"))
                report.Watermarks.Add(CreateTextWatermark("Second Watermark", "Watermark2"))
                report.WatermarkId = "Watermark2"
                report.ShowRibbonPreviewDialog()
        End Sub
    ' ...
        Private Function CreateTextWatermark(ByVal text As String, ByVal id As String) As XRWatermark
            Dim textWatermark As New XRWatermark()
            textWatermark.Text = text
            textWatermark.Id = id
            textWatermark.TextDirection = DirectionMode.ForwardDiagonal
            textWatermark.Font = New DXFont("Verdana", 36)
            textWatermark.TextPosition = WatermarkPosition.InFront
            textWatermark.ForeColor = Color.Red
            Return textWatermark
        End Function
End Class

Bind WatermarkId to an expression to apply watermarks stored in the collection to specific report pages.

The following code snippet adds different watermarks to the first, odd, and even pages of XtraReport:

csharp
using DevExpress.XtraReports.UI;
// ...
public partial class XtraReport : DevExpress.XtraReports.UI.XtraReport {
   private void XtraReport_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e){
            XtraReport report = new XtraReport();
            ExpressionBinding watermarksBinding = new ExpressionBinding();
            watermarksBinding.EventName = nameof(BeforePrint);
            // Specify an expression that is rendered within the BeforePrint event.
            watermarksBinding.Expression = "`Iif([Arguments.PageIndex]=0,'Watermark_0',Iif([Arguments.PageIndex]%2=0,'Watermark_1','Watermark_2'))`";
            watermarksBinding.PropertyName = nameof(WatermarkId);
            report.ExpressionBindings.Add(watermarksBinding);
    }
}
vb
Imports DevExpress.XtraReports.UI
' ...
Partial Public Class XtraReportCategories
    Inherits DevExpress.XtraReports.UI.XtraReport

   Private Sub XtraReport_BeforePrint(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
            Dim report As New XtraReport()
            Dim watermarksBinding As New ExpressionBinding()
            watermarksBinding.EventName = NameOf(BeforePrint)
            ' Specify an expression that is rendered within the BeforePrint event.
            watermarksBinding.Expression = "`Iif([Arguments.PageIndex]=0,'Watermark_0',Iif([Arguments.PageIndex]%2=0,'Watermark_1','Watermark_2'))`"
            watermarksBinding.PropertyName = NameOf(WatermarkId)
            report.ExpressionBindings.Add(watermarksBinding)
   End Sub
End Class

The image below shows the result.

Review the following help topic for more information on how to bind expressions to report elements: Data Binding Modes.

See Also

XtraReport Class

XtraReport Members

DevExpress.XtraReports.UI Namespace