Back to Devexpress

Hide Properties from the Report Designer

xtrareports-119459-desktop-reporting-wpf-reporting-end-user-report-designer-for-wpf-api-and-customization-hide-properties-from-the-report-designer.md

latest7.6 KB
Original Source

Hide Properties from the Report Designer

  • Feb 01, 2024
  • 3 minutes to read

Tip

Online Example : WPF Report Designer - How to hide properties of reports and their elements

This sample illustrates how to hide properties of a report and its controls from the End-User Report Designer‘s Properties panel.

Handle the static XtraReport.FilterComponentProperties event to remove items from the Properties tab.

Use the ExpressionBindingDescriptor.HidePropertyDescriptions method to remove properties from the Expressions tab available when the UserDesignerOptions.DataBindingMode is set to DataBindingMode.Expressions or DataBindingMode.ExpressionsAdvanced.

xaml
<Window x:Class="HidePropertiesExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:dxrud="http://schemas.devexpress.com/winfx/2008/xaml/reports/userdesigner"
        xmlns:local="clr-namespace:HidePropertiesExample"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <dxrud:ReportDesigner x:Name="reportDesigner" />
    </Grid>
</Window>
csharp
using System.Windows;
using DevExpress.XtraReports.Expressions;
using DevExpress.XtraReports.UI;

namespace HidePropertiesExample {
    public partial class App : Application {
        protected override void OnStartup(StartupEventArgs e) {
            // For XRLabel controls, hide the Background Color and Tag properties from the Expressions tab.
            ExpressionBindingDescriptor.HidePropertyDescriptions(typeof(XRLabel), "BackColor", "Tag");
            base.OnStartup(e);
        }
    }
}
csharp
using System;
using System.ComponentModel;
using System.Windows;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.UserDesigner;

namespace HidePropertiesExample {

    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
            var report = new XtraReport();
            // Handle the static FilterComponentProperties event to filter the Properties panel.
            XtraReport.FilterComponentProperties += XtraReport_FilterComponentProperties;
            reportDesigner.OpenDocument(report);
        }

        static void XtraReport_FilterComponentProperties(object sender, FilterComponentPropertiesEventArgs e) {
            // Hide the Scripts property for all report elements.
            HideProperty("Scripts", e);

            // Hide the ReportSource and ReportSourceUrl properties for subreports. 
            if (e.Component is XRSubreport) {
                HideProperty("ReportSource", e);
                HideProperty("ReportSourceUrl", e);
            }

            // Hide the Name property for XRLabel controls.
            if(e.Component is XRLabel) {
                HideProperty("Name", e);
            }
        }

        static void HideProperty(String propertyName,
            FilterComponentPropertiesEventArgs filterComponentProperties) {
            PropertyDescriptor oldPropertyDescriptor =
                filterComponentProperties.Properties[propertyName] as PropertyDescriptor;
            if(oldPropertyDescriptor != null) {
                // Substitute the current property descriptor with a custom one with the BrowsableAttribute.No attribute.
                filterComponentProperties.Properties[propertyName] = TypeDescriptor.CreateProperty(
                    oldPropertyDescriptor.ComponentType,
                    oldPropertyDescriptor,
                    new Attribute[] { BrowsableAttribute.No });
            } else {
                // If the property descriptor cannot be substituted, remove it from the Properties collection.
                filterComponentProperties.Properties.Remove(propertyName);
            }
        }
    }
}
vb
Imports System
Imports System.ComponentModel
Imports System.Windows
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraReports.UserDesigner

Namespace HidePropertiesExample

    Partial Public Class MainWindow
        Inherits Window

        Public Sub New()
            InitializeComponent()
            Dim report = New XtraReport()
            ' Handle the static FilterComponentProperties event to filter the Properties panel.
            AddHandler XtraReport.FilterComponentProperties, AddressOf XtraReport_FilterComponentProperties
            reportDesigner.OpenDocument(report)
        End Sub

        Private Shared Sub XtraReport_FilterComponentProperties(ByVal sender As Object, ByVal e As FilterComponentPropertiesEventArgs)
            ' Hide the Scripts property for all report elements.
            HideProperty("Scripts", e)

            ' Hide the ReportSource and ReportSourceUrl properties for subreports. 
            If TypeOf e.Component Is XRSubreport Then
                HideProperty("ReportSource", e)
                HideProperty("ReportSourceUrl", e)
            End If

            ' Hide the Name property for XRLabel controls.
            If TypeOf e.Component Is XRLabel Then
                HideProperty("Name", e)
            End If
        End Sub

        Private Shared Sub HideProperty(ByVal propertyName As String, ByVal filterComponentProperties As FilterComponentPropertiesEventArgs)
            Dim oldPropertyDescriptor As PropertyDescriptor = TryCast(filterComponentProperties.Properties(propertyName), PropertyDescriptor)
            If oldPropertyDescriptor IsNot Nothing Then
                ' Substitute the current property descriptor with a custom one with the BrowsableAttribute.No attribute.
                filterComponentProperties.Properties(propertyName) = TypeDescriptor.CreateProperty(oldPropertyDescriptor.ComponentType, oldPropertyDescriptor, New Attribute() { BrowsableAttribute.No })
            Else
                ' If the property descriptor cannot be substituted, remove it from the Properties collection.
                filterComponentProperties.Properties.Remove(propertyName)
            End If
        End Sub
    End Class
End Namespace
vb
Imports System.Windows
Imports DevExpress.XtraReports.Expressions
Imports DevExpress.XtraReports.UI

Namespace HidePropertiesExample
    Partial Public Class App
        Inherits Application

        Protected Overrides Sub OnStartup(ByVal e As StartupEventArgs)
            ' For XRLabel controls, hide the Background Color and Tag properties from the Expressions tab.
            ExpressionBindingDescriptor.HidePropertyDescriptions(GetType(XRLabel), "BackColor", "Tag")
            MyBase.OnStartup(e)
        End Sub
    End Class
End Namespace