Connect to Child Event
Hi! I'm trying to create a TreeView and listen to its TreeViewItems Expand event. In WPF, it's as simple as:
How do we connect to this event via code-behind in Noesis?
Code: Select all
<TreeView TreeViewItem.Expanded="OnItemExpanded" />
Re: Connect to Child Event
Have you tried overriding ConnectEvent as described in the Events Tutorial ?
Re: Connect to Child Event
Yes that's the first thing I tried, but the method gets invoked when the UserControl is initialized, with param (object source) pointing to the TreeView itself. But the event is for the future child items (TreeViewItem) once they're added.
The workaround is to register to the event by code
I can add a ticket if you want so ConnectEvent also gets invoked for children events when they're added?
The workaround is to register to the event by code
Code: Select all
MyTreeView.AddHandler(TreeViewItem.ExpandedEvent, new RoutedEventHandler(OnTreeViewExpanded));
Re: Connect to Child Event
Yes, please, add a ticket for this. Thank you!
-
sfernandez
Site Admin
- Posts: 3008
- Joined:
Re: Connect to Child Event
Hello, I want to mention that we already define a macro in C++ for attached events to be used in ConnectEvent:
And for C#, the code you posted is the expected behavior (the routed event will bubble up the tree from the TreeViewItem until it reaches the TreeView, so it will be processed for any TreeViewItem):
We need to explain this in the tutorial too.
Code: Select all
bool ConnectEvent(BaseComponent* source, const char* event, const char* handler) override
{
NS_CONNECT_ATTACHED_EVENT(TreeViewItem, Expanded, OnTreeViewExpanded);
return false;
}
Code: Select all
protected override bool ConnectEvent(object source, string eventName, string handlerName)
{
if (eventName == "Expanded" && handlerName == "OnTreeViewExpanded")
{
((TreeView)source).AddHandler(TreeViewItem.ExpandedEvent, new RoutedEventHandler(OnTreeViewExpanded));
}
}
Re: Connect to Child Event
Yes this is how I ended doing it. Thank you!
I don't think a ticket is necessary anymore, but yes explaining it in the tutorial would be great for future users.
I don't think a ticket is necessary anymore, but yes explaining it in the tutorial would be great for future users.
-
sfernandez
Site Admin
- Posts: 3008
- Joined:
Re: Connect to Child Event
We've updated the events tutorial so documentation will be fixed in the next release, thanks for your feedback.
Who is online
Users browsing this forum: Bing [Bot] and 2 guests