Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1350
Disable hot tracking for certain ribbon tabs
posted

Hi all,

I try to "disable" some ribbon tabs under certain conditions, e.g. the user is in a special mode, then he can no longer use Ribbon Tab-3 and Ribbon Tab-5. However these tabs should remain visible. I managed this by placing a boolean value (enabled = true/false) in the tabs Tag property and handling the event BeforeRibbonTabSelected.So the user can no longer select those tabs.

So far so good! Now I want to disable also the hot tracking for those "disabled" tabs and change the caption text of those tabs to a somehow disabled appearance.

How can can I do this ? Any ideas? DrawFilter?

Thanks! Regards

Michael

Parents
  • 1350
    Offline posted

    In the meantime I guess I may have found somekind of a solution for it via a DrawFilter.

    if(drawPhase == DrawPhase.BeforeDrawBackColor)
    {
        if(drawParams.Element is RibbonTabItemUIElement)
        {
            // Get the underlying ribbon tab control
            RibbonTab tab = drawParams.Element.GetContext(typeof(RibbonTab)) as RibbonTab;

            if(tab != null)
            {
                // Extract ribbon info object from Tag property
                if(tab.Tag != null && tab.Tag is RibbonTabInfo)
                {
                    RibbonTabInfo tabInfo = (RibbonTabInfo) tab.Tag;

                    // Get caption text UI element
                    ImageAndTextDependentTextUIElement captionUIElem =
                            drawParams.Element.GetDescendant(typeof(ImageAndTextDependentTextUIElement)) as ImageAndTextDependentTextUIElement;
                    if(captionUIElem != null)
                    {
                        // Update the enabled field of the UI Element, either disable or re-enable it
                        captionUIElem.Enabled = tabInfo.Enabled;
                    }

                    if(!tabInfo.Enabled)
                    {
                        // Prevent drawing of the background at all
                        return true;
                    }
                }
            }
        }
    }

    Regards

    Michael

Reply Children
No Data