Completed
Last Updated: 05 Feb 2019 15:48 by ADMIN
ADMIN
Hristo
Created on: 05 Dec 2018 07:29
Category: LayoutControl
Type: Feature Request
1
ADD. RadLayoutControl - expose API specifying whether items can be hidden or not
Hide Item option in the context menu should not be present for those items. We should also consider a cancellable ItemHiding event. The custom control below handles this scenario:

public class CustomRadLayoutControl : RadLayoutControl
{
    public override string ThemeClassName
    {
        get
        {
            return typeof(RadLayoutControl).FullName;
        }
    }

    protected override void InitializeDropDownMenu()
    {
        FieldInfo hideMenuItemFi = typeof(RadLayoutControl).GetField("hideMenuItem", BindingFlags.Instance | BindingFlags.NonPublic);
        RadMenuItem hideMenuItem = hideMenuItemFi.GetValue(this) as RadMenuItem;

        if (hideMenuItem == null)
        {
            hideMenuItemFi.SetValue(this, new RadMenuItem(LayoutControlLocalizationProvider.CurrentProvider.GetLocalizedString(LayoutControlStringId.ContextMenuCustomize)));
            hideMenuItem = hideMenuItemFi.GetValue(this) as RadMenuItem;
        }

        hideMenuItem.Click += customizeItem_Click;

        RadDropDownMenu menu = typeof(RadLayoutControl).GetField("dropDownMenu", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this) as RadDropDownMenu;
        menu.Items.Add(hideMenuItem);
    }

    private void customizeItem_Click(object sender, EventArgs e)
    {
        if (this.AllowCustomize)
        {
            this.ShowCustomizeMenuDialog();
        }
    }

    private void ShowCustomizeMenuDialog()
    {
        if (this.CustomizeDialog.Visible)
        {
            return;
        }

        this.ShowCustomDragOverlay();
        this.CustomizeDialog.Owner = this.FindForm();
        ThemeResolutionService.ApplyThemeToControlTree(this.CustomizeDialog, this.ThemeName);

        if (this.CustomizeDialog.Location == Point.Empty)
        {
            this.CustomizeDialog.Location = GetInitialCustomizeDialogLocation();
        }

        this.CustomizeDialog.Show();
        this.CustomizeDialog.RightToLeft = this.RightToLeft;
    }

    private void ShowCustomDragOverlay()
    {
        FieldInfo dragOverlayFi = typeof(RadLayoutControl).GetField("dragOverlay", BindingFlags.Instance | BindingFlags.NonPublic);
        LayoutControlDraggableOverlay dragOverlay = dragOverlayFi.GetValue(this) as LayoutControlDraggableOverlay;

        if (dragOverlay == null)
        {
            dragOverlayFi.SetValue(this, new CustomLayoutControlDraggableOverlay(this));
            dragOverlay = dragOverlayFi.GetValue(this) as LayoutControlDraggableOverlay;
        }

        dragOverlay.ThemeName = this.ThemeName;
        dragOverlay.UpdatePreview();

        dragOverlay.Dock = DockStyle.Fill;
        ((RadLayoutControlControlCollection)this.Controls).AddInternal(dragOverlay);
        dragOverlay.Visible = true;
        dragOverlay.BringToFront();
        this.PerformLayout();
        this.Refresh();
    }

}

public class CustomLayoutControlDraggableOverlay : LayoutControlDraggableOverlay
{
    private RadMenuItem hideMenuItem;


    public CustomLayoutControlDraggableOverlay(RadLayoutControl owner) 
        : base(owner)
    {
        RadDropDownMenu contextMenu = typeof(LayoutControlDraggableOverlay).GetField("contextMenu", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this) as RadDropDownMenu;
        contextMenu.Items.Clear();

        this.hideMenuItem = new RadMenuItem(LayoutControlLocalizationProvider.CurrentProvider.GetLocalizedString(LayoutControlStringId.ContextMenuHideItem));
        this.hideMenuItem.Text = LayoutControlLocalizationProvider.CurrentProvider.GetLocalizedString(LayoutControlStringId.ContextMenuHideItem);
        this.hideMenuItem.Click += hideMenuItem_Click;
        contextMenu.Items.Add(hideMenuItem);
        contextMenu.DropDownOpening += ContextMenu_DropDownOpening;
    }

    private void ContextMenu_DropDownOpening(object sender, CancelEventArgs e)
    {
        if (this.SelectedItems.Count == 1 && this.SelectedItems[0].Name == "layoutControlItem4")
        {
            e.Cancel = true;
        }
    }

    private void hideMenuItem_Click(object sender, EventArgs e)
    {
        foreach (DraggableLayoutControlItem item in this.SelectedItems)
        {
            if (item.Name == "layoutControlItem4")
            {
                continue;
            }

            ((CustomRadLayoutControl)this.Owner).HideItem(item.AssociatedItem);
        }

        this.UpdatePreview();
    }
}
1 comment
Dimitar
Posted on: 05 Feb 2019 15:47

Hello,

New AllowHide property in the base LayoutControlItemBase class will be available in Telerik UI for WinForms version R1 2019 SP1. It can be used this way:

this.layoutControlItem4.AllowHide = false;

 
New ItemHiding event in RadLayoutControl:
private void RadLayoutControl1_ItemHiding(object sender, LayoutControlItemHidingEventArgs e)
{
    if (e.Item.Name == "layoutControlItem1")
    {
        e.Cancel = true;
    }
}