Skip to main content
All docs
V26.1
  • Manage Button Visibility in a Blazor Lookup Property Editor

    • 3 minutes to read

    XAF manages the visibility of New and Edit buttons inside an ASP.NET Core Blazor Lookup Property Editor according to Security System permissions, business object settings, and Action parameters.

    Lookup Property Editor in a Detail View
    The Edit and New buttons in the Blazor Lookup Property Editor in Detail View
    Lookup Property Editor in a List View with in-place editing enabled
    The Edit and New buttons in the Blazor Lookup Property Editor in List View

    Call the following LookupPropertyEditor methods to hide or display these buttons:

    HideNewButton
    Hides the New button.
    HideEditButton
    Hides the Edit button.
    ResetNewButtonVisibility
    Displays the hidden New button.
    ResetEditButtonVisibility
    Displays the hidden Edit button.

    Note

    The Edit button acts as a clickable link. Use Ctrl + click or click the middle mouse button to open the referenced object in a new browser tab. To disable this behavior, add a Controller to your application, as described in the following topic: Hide Hyperlinks in Lookup Controls.

    In a Detail View

    When LookupEditorMode is set to AllItems or Auto, and View mode is enabled, XAF displays the Lookup Property Editor as a Text Box with an Edit button. When the user clicks the button, XAF changes the editor to a ComboBox.

    Buttons in the Lookup Property Editor

    Each mode uses a different collection to maintain editor buttons: the ViewModeButtons collection in View mode, the Buttons collection in Edit mode. Check which collection is available to determine the current mode.

    Call HideNewButton and HideEditButton in the Controller’s OnActivated method to hide the New and Edit buttons. Note that XAF displays referenced objects as clickable links. Disable the ShowLink property to display referenced objects as plain text.

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Blazor.Editors;
    using DevExpress.ExpressApp.Blazor.Utils;
    // ...
    public class LookupActionVisibilityController : ViewController {
        protected override void OnActivated() {
            base.OnActivated();
            View.CustomizeViewItemControl<LookupPropertyEditor>(this, e => {
                // Hide New and Edit buttons in Edit mode
                if (e.Buttons != null) {
                    e.HideNewButton();
                    e.HideEditButton();
                }
                // Show referenced objects as text in View mode
                else {
                    e.ShowLink = false;
                }
            });
        }
    }
    

    These changes apply to Detail Views and to List Views when in-place editing is enabled. To apply the changes for a particular View, use the CustomizeViewItemControl<T>(View, Controller, Action<T>) method.

    Manage Button Visibility in Actions

    The following code snippet uses Actions to manage lookup editor button visibility:

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Actions;
    using DevExpress.ExpressApp.Blazor.Editors;
    using DevExpress.Persistent.Base;
    // ...
    public class LookupActionVisibilityController : ViewController<DetailView> {
        public LookupActionVisibilityController() {
            SimpleAction hideNewAction = new SimpleAction(this, "Hide New", PredefinedCategory.Edit);
            SimpleAction hideEditAction = new SimpleAction(this, "Hide Edit", PredefinedCategory.Edit);
            SimpleAction resetNewAction = new SimpleAction(this, "Reset New", PredefinedCategory.Edit);
            SimpleAction resetEditAction = new SimpleAction(this, "Reset Edit", PredefinedCategory.Edit);
            hideNewAction.Execute += (s, e) => {
                View.CustomizeViewItemControl<LookupPropertyEditor>(this, e => {
                    e.HideNewButton();
                });
            };
            hideEditAction.Execute += (s, e) => {
                View.CustomizeViewItemControl<LookupPropertyEditor>(this, e => {
                    e.HideEditButton();
                });
            };
            resetNewAction.Execute += (s, e) => {
                View.CustomizeViewItemControl<LookupPropertyEditor>(this, e => {
                    e.ResetNewButtonVisibility();
                });
            };
            resetEditAction.Execute += (s, e) => {
                View.CustomizeViewItemControl<LookupPropertyEditor>(this, e => {
                    e.ResetEditButtonVisibility();
                });
            };
        }
    }
    
    See Also