What am I doing wrong here?


#1

I have a control that contains a GoView.
I have a node (LayerNode) which is my own definition which inherits GoTextNode.
I have the OnSingleClick event caught in the (LayerNode) node, but once I am done with my process I return false to raise the event to up the parent chain.
When I get the event in my control (the container for the GoView), the eventArgs returned to me has the e.GoObject defined as type GoText instead of GoTextNode. This is preventing me from casting the clicked object to my defined object that originally inherited the GoTextNode.
Why is this happening?


#2

Are you talking about the GoView.ObjectSingleClicked event? If the user clicks on the label, that GoText object is the object which got clicked. That’s why you see that as the event-args’s GoObject.
View events can happen on any object, so view event handlers need to be able to handle that. In the typical case you can just look at GoObject’s ParentNode. You can check if it’s the kind of node you care about, and then cast it. Look at the samples, which do this.
On the other hand, if you have “event handling” code in GoObject method overrides, then you do know exactly which object is getting that event. So an override of GoObject.OnSingleClick in the definition of a node class, such as in your LayerNode class, will automatically find out about single-click events that get bubbled up the parent-child part hierarchy from the actual child that got that event directly. This is convenient because most times when you want to find out when a node has gotten clicked, you really don’t care which child might have really gotten the click event.


#3

That explaination did it. I just had to expand my logic a bit to where I would say:
if (e.GoObject.GetType() != typeof(MyNode))
item = e.GoObject.ParentNode as MyNode;
else
item = e.GoObject as MyNode;
Thanks.