How to: Hide the 'Protected Content' Columns in a List View and Property Editors in a Detail View

This topic describes how to use the Conditional Appearance Module in order to hide List View columns and Detail View Property Editors that are prohibited by the Security System and display the 'Protected Content' placeholders. If you want to filter out the 'Protected Content' records at the ORM level, you can additionally use the How to: Change the Client-Side Security Mode from UI Level to Integrated in XPO applications example.

Note

The approach described in this topic is not supported by the Mobile platform.

  • Add the Conditional Appearance Module to the platform-agnostic module project (if it was not added before). To do this, invoke the Module Designer or Application Designer, and drag the ConditionalAppearanceModule item from the Toolbox to the Modules panel. Make sure to rebuild your solution after making changes in the Designer.
  • Implement the following Controller class in the platform-agnostic module project.

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Editors;
    using DevExpress.ExpressApp.ConditionalAppearance;
    // ...
    public class HideProtectedContentController : ViewController<ObjectView> {
        private AppearanceController appearanceController;
        protected override void OnActivated() {
            base.OnActivated();
            appearanceController = Frame.GetController<AppearanceController>();
            if(appearanceController != null) {
                appearanceController.CustomApplyAppearance += appearanceController_CustomApplyAppearance;
            }
        }
        protected override void OnDeactivated() {
            if(appearanceController != null) {
                appearanceController.CustomApplyAppearance -= appearanceController_CustomApplyAppearance;
            }
            base.OnDeactivated();
        }
        void appearanceController_CustomApplyAppearance(object sender, ApplyAppearanceEventArgs e) {
            if(e.AppearanceObject.Visibility == null || e.AppearanceObject.Visibility == ViewItemVisibility.Show) {
                if(View is ListView) {
                    if(e.Item is ColumnWrapper) {
                        if(!DataManipulationRight.CanRead(View.ObjectTypeInfo.Type,
                            ((ColumnWrapper)e.Item).PropertyName, null,
                            ((ListView)View).CollectionSource, View.ObjectSpace)) {
                            e.AppearanceObject.Visibility = ViewItemVisibility.Hide;
                        }
                    }
                }
                if(View is DetailView) {
                    if(e.Item is PropertyEditor) {
                        if(!DataManipulationRight.CanRead(View.ObjectTypeInfo.Type,
                            ((PropertyEditor)e.Item).PropertyName,
                            e.ContextObjects.Length > 0 ? e.ContextObjects[0] : null, null,
                            View.ObjectSpace)) {
                            e.AppearanceObject.Visibility = ViewItemVisibility.Hide;
                        }
                    }
                }
            }
        }
    }
    
Note
  • HideProtectedContentController may have a negative impact on the application performance in complex scenarios.
  • Hidden states of list view columns are persisted in user model differences. So, if you will eventually grant access to a certain property, the view model needs to be manually adjusted or reset.