I have a UserControl of type XamTabControl with multiple tabs and event SelectionChanged="mainTab_SelectionChanged"
Inside one of the above tabs, I have a UserControl (B) that in turn has a XamTabControl. No events associated with this tab control.
When I select the second tab in the above UserControl (B), the application hangs up. On stepping through, I notice that it keeps cycling through the mainTab_SelectionChanged event function in a never ending loop.
What is causing the switching of tabs in the child UserControl to trigger the SelectionChanged event of the parent UserControl? How do I prevent this?
Thanks.
Hello,
The SelectionChanged event is a buble event and it is expected to be triggered from child XamTabControl. In case that you want to restrict the bubbling I can suggest you two options to do this:
The first approach is to subscribe to both main and child XamTabControl's SelectionChanged and set the e.Handled property to true in the child_SelectionChanged event handler.
The second option is to subscribe to the mainTab.SelectionChanged event only. In the event handler you can check whether e.Source.Equals(sender)) and if it's not you can set the e.Handled to true. Here the sender should be the object where you assigned the handler, and ut e.Source should be where the event actually occurred.
I have prepared a simple sample application in order to test your scenario and I was not able to reproduce the hangs up you have reported. I have attached this project, where you can test my suggestions. If it is not an accurate demonstration of what you're trying to do, please feel free to modify it and send it back, or send a small sample project of your own if you have one.
Please let me know if I can provide any further assistance.
Sincerely,ZhivkoAssociate Software Developer
Perfect - thanks a lot.