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
25
Hide/Disable Navigation Splitter for Office2007 Style
posted

 Hello,

 Is there a way to hide or disable the Navigation Splitter in the the WinExplorerBar control when the Style property is set to Office2007?

 I was looking on the archived forums and there was a post a couple years back where someone stated that this is not possible - unless you use a CreationFilter. 

 Is this the case for the v7.3 as well?  If so, can someone provide a sample of creating a CreationFilter to accomplish this?

Thanks in advance! 

Parents
No Data
Reply
  • 69832
    Offline posted

    You could remove the element using a creation filter, but the caviat there is that the space it occupies will be unavailable to you, and the contorl's background will show in that area.

    The following code sample demonstrates how to use the IUIElementCreationFilter interface to replace the existing element with one that looks and behaves as if it were disabled (assign an instance of this class to the control's CreationFilter property):

     #region DisabledNavigationBarSplitterCreationFilter
    /// <summary>
    /// IUIElementCreationFilter implementation which disables the splitter bar
    /// for the OutlookNavigationPane style ExplorerBar.
    /// </summary>
    public class DisabledNavigationBarSplitterCreationFilter : IUIElementCreationFilter
    {
        #region Member variables
        private DisabledNavigationSplitterBarUIElement recycledSplitterBarElement = null;
        private Color disabledColor = Color.Empty;
        #endregion Member variables

        #region Constructor
        /// <summary>
        /// Creates a new instance of the class.
        /// </summary>
        public DisabledNavigationBarSplitterCreationFilter( Color disabledColor )
        {
            this.disabledColor = disabledColor;
        }
        #endregion Constructor

        #region IUIElementCreationFilter implementation

        void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent)
        {
            GroupAreaUIElement groupAreaElement = parent as GroupAreaUIElement;

            if ( groupAreaElement != null )
            {
                //  Get the default NavigationSplitterBarUIElement and remove it
                UIElementsCollection childElements = groupAreaElement.ChildElements;

                NavigationSplitterBarUIElement defaultSplitterElement = groupAreaElement.GetDescendant( typeof(NavigationSplitterBarUIElement) ) as NavigationSplitterBarUIElement;

                if ( defaultSplitterElement != null )
                {
                    Rectangle rect = defaultSplitterElement.Rect;

                    childElements.Remove( defaultSplitterElement );

                    //  Set the bounds of the DisabledNavigationSplitterBarUIElement
                    //  to the same bounds as the defualt element, and add it.
                    if ( this.recycledSplitterBarElement == null )
                        this.recycledSplitterBarElement = new DisabledNavigationSplitterBarUIElement( groupAreaElement, this.disabledColor );

                    this.recycledSplitterBarElement.Rect = rect;

                    childElements.Add( this.recycledSplitterBarElement );
                }

            }
        }


        bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent)
        {
            //  Grab the existing DisabledNavigationSplitterBarUIElement, if there is one,
            //  so we can reduce object instantiation overhead by reusing an existing instance.
            GroupAreaUIElement groupAreaElement = parent as GroupAreaUIElement;

            if ( groupAreaElement != null )
                this.recycledSplitterBarElement = groupAreaElement.GetDescendant( typeof(DisabledNavigationSplitterBarUIElement) ) as DisabledNavigationSplitterBarUIElement;

            return false;
        }

        #endregion IUIElementCreationFilter implementation

        #region DisabledNavigationSplitterBarUIElement
        /// <summary>
        /// NavigationSplitterBarUIElement-derived element with a disabled appearance,
        /// and which cannot be dragged.
        /// </summary>
        public class DisabledNavigationSplitterBarUIElement : NavigationSplitterBarUIElement
        {
            private Color disabledColor = Color.Empty;

            /// <summary>
            /// Creates a new instance of the class.
            /// </summary>
            public DisabledNavigationSplitterBarUIElement( UIElement parent, Color disabledColor ) : base( parent )
            {
                this.disabledColor = disabledColor;
            }

            /// <summary>
            /// Overridden to do nothing, which effectively disables the element.
            /// </summary>
            protected override void OnMouseMove(MouseEventArgs e){}

            /// <summary>
            /// Overridden to make the element appear disabled
            /// </summary>
            protected override void InitAppearance(ref AppearanceData appearance, ref AppearancePropFlags requestedProps)
            {
                base.InitAppearance(ref appearance, ref requestedProps);

                Color disabledColor = this.disabledColor.IsEmpty == false ? this.disabledColor : Color.Gray;

                appearance.BackColor = disabledColor;
                appearance.BackColor2 = disabledColor;
            }

            /// <summary>
            /// Returns null so that the 'SizeNS' cursor is not shown.
            /// </summary>
            public override Cursor Cursor { get { return null; } }

        }
        #endregion DisabledNavigationSplitterBarUIElement
    }
    #endregion DisabledNavigationBarSplitterCreationFilter

Children