Hello, I want to mention that we already define a macro in C++ for attached events to be used in ConnectEvent:
bool ConnectEvent(BaseComponent* source, const char* event, const char* handler) override
{
NS_CONNECT_ATTACHED_EVENT(TreeViewItem, Expanded, OnTreeViewExpanded);
return false;
}
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):
protected override bool ConnectEvent(object source, string eventName, string handlerName)
{
if (eventName == "Expanded" && handlerName == "OnTreeViewExpanded")
{
((TreeView)source).AddHandler(TreeViewItem.ExpandedEvent, new RoutedEventHandler(OnTreeViewExpanded));
}
}
We need to explain this in the tutorial too.