Hello,
I have a UltraTree(default tree view) where I would like to hide the rightimages of a node when expanded, and then show the image(s) again once collapsed. The tree is unbound(populated on the fly), and it is not workable to delete the images and then re add them as they are specific to that node(the appropriate images cannot be determined without completely repopulating the tree). any help would be greatly appreciated!
Thanks and Cheers!
Rick
Hi Rick,
I whipped up some quick sample code for you.
this.ultraTree1.CreationFilter = new MyCreationFilter();
public class MyCreationFilter : IUIElementCreationFilter { void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent) { var nodeSelectableAreaUIElement = parent as NodeSelectableAreaUIElement; if (null == nodeSelectableAreaUIElement) return; var node = nodeSelectableAreaUIElement.GetContext(typeof(UltraTreeNode)) as UltraTreeNode; if (null == node) return; // If the node is collapsed, do nothing. if (false == node.Expanded) return; // This is something of a hack. There's no way to determined whether an ImageUIElement // is for a RightImage, LeftImage, or the node's appearance. So I am getting the // right edge of the TextUIElement here and then we will only remove image // elements that are to the right of it. var textUIElement = parent.GetDescendant(typeof(TextUIElement)) as TextUIElement; int thresholdX = null != textUIElement ? textUIElement.Rect.Right : 0; // If the node is expanded, remove all of the images. // Removing items from a collection inside a ForEach loop is not a good idea. // So instead, just build a list of the elements we want to remove. List<UIElement> elementsToRemove = new List<UIElement>(); foreach (UIElement element in parent.ChildElements) { if (element is ImageUIElement && element.Rect.Left >= thresholdX) { elementsToRemove.Add(element); } } // Now remove the elements we marked for removal. foreach (UIElement elementToRemove in elementsToRemove) parent.ChildElements.Remove(elementToRemove); } bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent) { // do nothing. return false; } }
Hi Mike,
As I though more about it, I think that I may be able utilize the DrawFilter or Creation Filter to Hide the images. Do you happen to have an example of how I would do this? I have not worked with the DrawFilter or CreationFilter before.
Rhanks,
rick
Thanks for the quick reply!
There's no property to hide an image in the ImagesRight collection.
The easiest thing to do would be to handle the BeforeExpand and BeforeCollapse methods and add / remove the images.
Another option would be to use a DrawFilter or CreationFilter to hide the images from the display, but this would leave a space where the images would have been. So I think the first option is better.