DxContextMenu.VisibleExpression Property

OBSOLETE

This property is obsolete now. Add the DataMappings tag to markup, define a collection of DxContextMenuDataMapping items, and map item properties to data source fields instead.

Specifies a lambda expression that returns a Boolean value. This value indicates whether an item is visible.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v21.1.dll

Declaration

[Browsable(false)]
[Obsolete("This property is obsolete now. Add the DataMappings tag to markup, define a collection of DxContextMenuDataMapping items, and map item properties to data source fields instead.")]
[Parameter]
public Expression<Func<object, bool>> VisibleExpression { get; set; }

Property Value

Type Description
Expression<Func<Object, Boolean>>

A lambda expression that returns a Boolean value: true if an item is visible; otherwise, false.

Remarks

When the Context Menu component is bound to a data source, use the VisibleExpression property to specify a lambda expression that returns a Boolean value: true if the item is visible; otherwise, false.

<DxContextMenu Data="@MenuItems"
               VisibleExpression="(item => (item as TextFormattingMenuItem).Visible)">
</DxContextMenu>

@code {
    List<TextFormattingMenuItem> menuItems;
    TextFormatting Formatting { get; set; } = new TextFormatting();

    public class TextFormatting {
        public string FontFamily { get; set; }
        public int FontSize { get; set; }
        public Dictionary<string, bool> Decoration { get; } = new Dictionary<string, bool>() {
            { "Bold", false },
            ...
            { "Overline" , false }
        };
    }

    abstract class TextFormattingMenuItem {
        protected TextFormattingMenuItem(TextFormatting textFormatting, string text) {
            TextFormatting = textFormatting;
            Text = text;
        }

        public TextFormatting TextFormatting { get; }
        public string Text { get; }
        public bool Visible { get; set; }
    }

    List<TextFormattingMenuItem> MenuItems { 
        get { 
            if (menuItems == null) {
                menuItems = new List<TextFormattingMenuItem>() {
                    new TextFormattingParentMenuItem(Formatting, "Font", new List<TextFormattingMenuItem>() {
                        new FontFamilyMenuItem(Formatting, "Times New Roman", "Times New Roman"),
                        ...
                        new FontFamilyMenuItem(Formatting, "Default", null) { Visible = false }
                    }),
                    new TextFormattingParentMenuItem(Formatting, "Style", new List<TextFormattingMenuItem>() {
                        new TextDecorationMenuItem(Formatting, "Bold", "Bold"),
                        ...
                        new TextDecorationMenuItem(Formatting, "Strikethrough", "Strikethrough")
                    }),
                    new ClearFormattingMenuItem(Formatting) { Visible = false } 
                };
            }
            return menuItems;
        }
    }
}

Run Demo: Context Menu - Data Binding

See Also