<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>
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);
}
}
}
}
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