I am planning to show the RightImage on a node hottrack and upon a node selection, i.e all other nodes in my treeview won't show any RightImage.
And next when user clicks on Image I want to show ContextMenu.
The problems that I have are..1) How to set a rightImage on hottrack (I am able to do it upon node selection) 2)How to catch the Image click event?
Hello bsanga,
Could you please review the sample attached to this post and see if it meets your requirements. Please feel free to let me know if I misunderstood you or if you have any other questions.
Hi Boris,
The attached example met one of my requirements, however in the example rightimage is being added in AfterActivate event, that means untill I Select (or activate) the node I won't see the image, my requirement is to show the right image on hottrack. Or is there any way to make a HottrackNode as an ActiveNode, so that AfterActivate will fire?
Hello,
The following works for me:
if (e.Element is ImageUIElement && e.Element.Parent is NodeSelectableAreaUIElement)
{
((ImageUIElement)e.Element).Image;
}
In the MouseEnterElement event;
Hi All - I took a look at the samples, but I am not sure I understand if the question regarding which image(the right or left) image of the node was clicked. I would like to be able to determine which one was clicked but I am not having any luck. Looking forward to your reply.
Cheers!
rick
Hi Rick,
The image element doesn't have any context to allow you to get back to the collection.
So you have a couple of option. You could get the image from the element and then compare it to the images you are using and see if it matches. This assumes that you are using a single instance of the image for all of the nodes.
Another option would be to examine the Rect of the image element within it's parent and compare it to the other elements inside the same parent. Presumably, there is a NodeTextUIElement inside the parent. If the image element's rect is to the right of the NodeTextUIElement, you know you are dealing with an image in the RightImages collection. And if it's to the left, you know you are dealing with the LeftImages collection.
If you only have one image left and one image right, I'd probably recommend the latter approach.
private void ultraTree1_MouseClick(object sender, MouseEventArgs e) { UltraTree tree = (UltraTree)sender; UIElement element = tree.UIElement.LastElementEntered; ImageUIElement imageUIElement = element as ImageUIElement; if (null != imageUIElement) { NodeSelectableAreaUIElement parent = element.Parent as NodeSelectableAreaUIElement; if (null != parent) { NodeTextUIElement nodeTextUIElement = parent.GetDescendant(typeof(NodeTextUIElement)) as NodeTextUIElement; if (null != nodeTextUIElement) { if (imageUIElement.Rect.Left > nodeTextUIElement.Rect.Left) Debug.WriteLine("ImageRight"); else Debug.WriteLine("ImageLeft"); } } } }
Mike - that works perfect. Thanks for you quick reply and appreciate your help!
Cheers
Hi,
I'm glad that works for you. Just to be safe, you might want to test this out in a case where horizontal scrolling is available in the tree. I don't think it will be a problem, but some UIElements do not create their child elements that are out of view. So if a node is scrolled horizontally in such a way that the RightImages are visible and the text is not, this code might have a problem. And the same could be true if the left image is visible, but the text is not.
I don't think these will be a problem, but if the tree in your app has a scrollbar, it might be worth checking out, just to be safe.