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
90
Navigation Filter for UltraTree
posted

Hi!

I created a CreationFilter for UltraTree that does the following:

1. Makes the TreeNode Area wider and higher and moves it a bit left, so I would get a nicer looking selectable area:

2. Adds a button to the top-Node of the Tree as a child control:

All is well, but strangely if I use both components together, I can't get OnHover action of the button anymore and to activate it I need to click two times.

Here is the CreationFilter code:

private void OffsetElements(UIElement parent)
        {
            if (parent is TreeNodeUIElement)
            {
                Rectangle newRect = parent.Rect;
                newRect.Width = parent.Control.Width;
                newRect.Height = 23;
                newRect.X = 0;
                parent.Rect = newRect;

                foreach (UIElement child in parent.ChildElements)
                {
                    int nLevel = (parent as TreeNodeUIElement).Node.Level;
                    Rectangle newRectChild = child.Rect;
                    newRectChild.X = newRectChild.X + nLevel * 19;
                    child.Rect = newRectChild;
                }

                CreateButton(parent);
            }
        }

        private void CreateButton(UIElement parent)
        {
            if ((parent as TreeNodeUIElement).Node.Level != 0)
                return;

            Appearance app = new Appearance
            {
                BackColor = Color.Transparent,
                ImageBackground = Properties.Resources.Cog_12x12,
                ImageBackgroundStyle = ImageBackgroundStyle.Centered,
                AlphaLevel = 0
            };

            ButtonUIElement oButtonNode = new ButtonUIElement(parent);
            oButtonNode.ElementClick += new UIElementEventHandler(button_ElementClick);
            parent.ChildElements.Add(oButtonNode);

            int x = parent.Rect.Width - 30;
            int y = parent.Rect.Y;

            Rectangle rectangle = new Rectangle(new Point(x, y), new Size(parent.Rect.Height, parent.Rect.Height));
            oButtonNode.Rect = rectangle;
            oButtonNode.Appearance = app;
        }

Could you hint me what am I doing wrong?

Parents
  • 469350
    Verified Answer
    Offline posted

    It's tough to say for sure without more information. There are a lot of variables here that you didn't mention, like what ViewStyle your tree is using and whether or not you are using themes. But I played around with your CreationFilter a bit and as it is, it doesn't work for me. I don't even see the selection getting extended like in your screen shots. So there's probably some other setting or variable in your application that is different from mine. 

    One thing I do see is that your CreationFilter is enlarging the direct child elements of the TreeNodeUIElement, but not the the entire descendant tree, and more importantly, not the TreeNodeUIElement itself. So I think that's probably why your button element is no responding to a mouse over - because it's being clipped by it's parent element. As a general rule, you never want a child element to extend outside of it's own parent. 

    I experimented a little but and I was able to get this working by doing three things in the CreationFilter: 
    1) Expand the width of the TreeNodeUIElement itself. 

    2) Expand the with of the NodeTextUIElement, which is the element that shows the selection color. 

    3) Add the button. 

    I am attaching a small sample project here. 


    WindowsFormsApp26.zip

Reply Children
No Data