Blog Post

Poof Goes the NavigationOverflowButtonAreaUIElement - Creation Filter Explained

Rising Cost of Real Estate - Adding (not covered) or Removing  Elements in your Windows Forms Application

So you have only so much screen space to work with and you could really do without that extra bar at the bottom of the Outlook style UltraExplorerBar.  You really do not have the time to go into the source code and recompile everything for such a feature.  There has to be a better alternative.  Right?  Since you decided to use the Infragistics toolset, you are in luck.  Since our controls are built on top of our Presentation Layer Framework, you can take advantage of a feature called a creation filter which allows you to keep certain elements from being created and/or allows you to create your own elements that you can embed in various areas of your controls. 

To better explain, you have this:

 image

but want this:

 image

Getting Started

Because this deals with removing an element,  you know you have to use a creation filter to accomplish this task.  First you create your class and have it implement the IUIElementCreationFilter interface.  It will generate two method stubs where you can hook into the various levels of elements in our controls.  BeforeCreateChildElements will be called for every element before child elements of the current element is created.  AfterCreateChildElements will be called after all the child elements are created and positioned.

Here is what your class will look like:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Infragistics.Win;

namespace ExplorerBar_CreationFilterCS

{

    class XPBar_CreationFilter:IUIElementCreationFilter

    {

        #region IUIElementCreationFilter Members

        public void AfterCreateChildElements(UIElement parent)

        {

        }

        public bool BeforeCreateChildElements(UIElement parent)

        {

            return false;

        }

        #endregion

    }

}

 

Hook it up

You have your class but now you have to tell the UltraExplorerBar to use that class.  This step is very simple but sometimes forgotten.  To do this, you just assign an instance of your class to the CreationFilter property off the control like so:

ultraExplorerBar1.CreationFilter = new XPBar_CreationFilter();

But that didn't do anything

Well we still didn't write any logic, so yes, we really haven't done anything yet.  To figure out what we need to do, we need to make use of a utility call the Infragistics UIElementViewer Utility.  More information on the tool and the download link can be found on Devin Rader's Blog here.

Doing Something

So let's use this spiffy new tool. Add the dialog to your toolbox (through drag drop or choose items) and drag the dialog onto your form.

image

Once on your form, you can show the dialog by calling the show method like so:

uiElementViewerDialog1.Show();

You then use the dialog by clicking on the binoculars and dragging it over the various areas of the Infragistics controls.  This will show you the current UIElement being inspected and where the current element exists in the tree of elements.

image

Using the information of the class name that represents each element and the hierarchy used to construct the control, you can begin to write the logic to remove that bottom element from your control.

Writing the Code

One of the simplest creation filters you can write is when you just remove an element.  To do that, in the BeforeCreateChildElements method, you check for the parent element and return true.  You can only do this if the element you are trying to remove does not have any siblings.  This is because the siblings will not be created in addition to the element you are interested in.  Since the element we are trying to remove does have a sibling we have to take an alternative method.

So BeforeCreateChildElements is out of the equation.  Let's take a look at AfterCreateChildElements.  In here, you want to do the same where you check for the parent type which is the NavigationAreaUIElement type in this case.  In that condition, you then call GetDescendant to retrieve the object so you can remove it from the ChildElements collection of the parent.

public void AfterCreateChildElements(UIElement parent)

{

    //checks to see if we have currently drawn the NavigationAreaUIElement's children

    //so we have access to its children which we need to modify

    if (parent is Infragistics.Win.UltraWinExplorerBar.NavigationAreaUIElement)

    {

        //gets the NavigationOverflowButtonAreaUIElement so that we can remove it

        Infragistics.Win.UIElement overarea = parent.GetDescendant(typeof(Infragistics.Win.UltraWinExplorerBar.NavigationOverflowButtonAreaUIElement));

        //if such a child exists we remove it and note its height

        if (overarea != null)

        {

            parent.ChildElements.Remove(overarea);

        }

    }           

}

When you run this code, you will notice that the control does not look quite as you would expect. 

image

Since Windows Forms elements are essentially absolutely positioned, you have to reposition/resize all the other elements like so:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Infragistics.Win;

namespace ExplorerBar_CreationFilterCS

{

    class XPBar_CreationFilter : IUIElementCreationFilter

    {

        private int offsetHeight;

        #region IUIElementCreationFilter Members

        public void AfterCreateChildElements(UIElement parent)

        {

            //checks to see if we have currently drawn the NavigationAreaUIElement's children

            //so we have access to its children which we need to modify

            if (parent is Infragistics.Win.UltraWinExplorerBar.NavigationAreaUIElement)

            {

                //gets the NavigationOverflowButtonAreaUIElement so that we can remove it

                Infragistics.Win.UIElement overarea = parent.GetDescendant(typeof(Infragistics.Win.UltraWinExplorerBar.NavigationOverflowButtonAreaUIElement));

                //if such a child exists we remove it and note its height

                if (overarea != null)

                {

                    offsetHeight = overarea.Rect.Height;

                    parent.ChildElements.Remove(overarea);

                }

                //gets the area that shows the groups contents

                Infragistics.Win.UIElement GroupArea = parent.Parent.GetDescendant(typeof(Infragistics.Win.UltraWinExplorerBar.GroupUIElement));

                //gets the splitter used by the group buttons and the group content area

                Infragistics.Win.UIElement splitter = parent.Parent.GetDescendant(typeof(Infragistics.Win.UltraWinExplorerBar.NavigationSplitterBarUIElement));

                //gets the area which houses the group buttons

                Infragistics.Win.UIElement area = parent.Parent.GetDescendant(typeof(Infragistics.Win.UltraWinExplorerBar.NavigationAreaUIElement));

                //offsets the group button area at the bottom by the offset amount

                area.Offset(0, offsetHeight);

                //offsets the splitter by the offset amount

                splitter.Offset(0, offsetHeight);

                //resizes the group contents area to expand to fill the empty space based on the offset amount

                GroupArea.Rect = new System.Drawing.Rectangle(GroupArea.Rect.Left, GroupArea.Rect.Top, GroupArea.Rect.Width, GroupArea.Rect.Height + offsetHeight);

            }

        }

        public bool BeforeCreateChildElements(UIElement parent)

        {

            return false;

        }

        #endregion

    }

}

This is a very powerful tool that lets you do virtually anything with our Windows Forms controls.  No property for that visual feature you want?  No problem.  Use a filter.

Oh By The Way...

There are three other types of filters out there.  I may write something on them in the future, but here are some links if you want a head start:

Draw Filter

Cursor Filter

Selection Strategy Filter

Some Samples in our Knowledge Base:

Creation Filters

Draw Filters

Sample uses the following:

-Infragistics NetAdvantage 2008 Volume 2 CLR 2.0

-Visual Studio 2008

Minimum requirements:

-Infragistics NetAdvantage

Get Sample here.


Posted 08-28-2008 4:57 PM by [Infragistics] Sung Kim
Filed under:

Add a Comment


Sign in to post a comment.