Hello,
I'm currently adding UltraExplorerBarGroups to an UltraExplorerBar by dragging items from an UltraTree. What I'd like to do is show a drop location indicator in the explorer bar when I'm adding a new item in between existing items. Basically, the same indicator when you drag groups around to rearrage their order. Thanks.
This can be done using either the IUIElementDrawFilter or IUIElementCreationFilter interfaces. The UltraTree samples that ship with the SDK include an UltraTree example of the IUIElementDrawFilter approach, which demonstrates the concept, but it refers to UltraTree rather than UltraExplorerBar.
To quickly explain how this could be done with a creation filter: There is already a UIElement class (ItemDropHighlightUIElement) that does the drawing, which you could use (to be honest it is a very simple element and using it will not save you a huge amount of time over creating your own). When you implement IUIElementCreationFilter, you would add one of these elements to the ItemAreaInnerUIElement's ChildElements collection. To know where it goes, you would have to track the item closest to the cursor position, which you can use the ItemFromPoint method to do.
Thanks for the response Brian. I haven't actually verified that this will work (clicked the wrong link), but I feel that I'm headed down the right path now. It'll take me some time to actually implement though it since I'm new to Infragistics controls.
Thanks again Brian. When AfterCreateChildElements is called and we get the child elements of the target ItemAreaInnerUIElement:
UIElementsCollection childElements = itemAreaElement.ChildElements;
childElements.Count is always 0, so the code in foreach never gets executed. Even when I modify the code so the DropHighlightElement object gets added as a child element, nothing is ever drawn.
A modified version that gets the line to draw, but I don't feel like the code is correct going by your previous posts and sample code. Am I doing something wrong here?
void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent){ // Kind of works. if (this.isDragging == false) return;
ItemAreaInnerUIElement itemAreaElement = parent as ItemAreaInnerUIElement;
if (itemAreaElement != null) { Point cursorPos = this.explorerBar.PointToClient(Control.MousePosition);
UltraExplorerBarGroup group = parent.GetContext(typeof(UltraExplorerBarGroup)) as UltraExplorerBarGroup;
// Hit test each group to see if the cursor is currently over it Rectangle groupRectangle = group.UIElement.Rect;
if (groupRectangle.Contains(cursorPos)) { DropHighlightElement dropHighlightElement = new DropHighlightElement(itemAreaElement);
Rectangle rect = groupRectangle; rect.Height = 2; rect.Y = rect.Top; dropHighlightElement.Rect = rect;
// Feels like I'm adding dropHighlightElement to the wrong UIElement here. group.UIElement.ChildElements.Add(dropHighlightElement); } }}
Your suspicion was correct, you don't want to add it to the GroupUIElement, you want to add it to the ItemAreaInnerUIElement. The reason the ChildElements collection is empty is because there are no items in the group.
What's the reasoning behind adding it to ItemAreaInnerUIElement and not GroupUIElement? Does it have something to do with draw regions or draw order?
Sorry for all the questions, but I'm new to using Infragistics controls and I haven't been able to locate a document that explains how all these elements relate/interact with one another. Thanks for all of your help so far.
Some UIElements are the physical manifestations of the objects exposed by the control; for example, the GroupUIElement is the physical manifestation of an UltraExplorerBarGroup. Many elements, GroupUIElement included, have constituent elements, such as the ItemAreaInnerUIElement and the UltraExplorerBarGroupHeaderUIElement. ItemAreaInnerUIElement just happens to be the element that contains the items, and in your original post you expressed the desire to show a drop location indicator in between existing items.
Ah, I think I'm starting to see where my confusion came from. What I really want to do is show a drop location in between existing *groups*, not items. Basically, in the empty/dead space in between groups controlled by the GroupSpacing property. lf that's the case, was I doing the correct thing when I added the drop indicator to the group's child elements? That is:
group.UIElement.ChildElements.Add(dropHighlightElement);