I´m creating a game in XNA with my own UI and its controls/components. Currently I have some problems with the event handling. Let me tell me the way I do it right now. Every object is handles as a component (also the form itself). Each component can implement an interface with a container which can contain a list of components (and so on and so on). An example: I have a form. On this form there is a TabControl. In this TabControl there are different TabPages and in these pages there are buttons.
I now have to handle my events that when I click on the button, the overlaying controls should not fire an event (like OnClick etc.).
How can I easily do that? I have a current function which runs recursively but only on two levels depth or something.
Here is my current function which is not working as expected:
private Boolean HandleComponentList(IComponentList parent) {
foreach (var singleItem in parent.Components.OrderByDescending(i => i.ID).Where(singleItem => singleItem.Visible))
{
// Cast item to IComponentList.
var castedList = singleItem as IComponentList;
// If list is not null (so it implements IComponentList), call HandleComponentList for Components in this control first.
if (castedList != null)
{
// If an event has been raised, break function.
var eventFound = HandleComponentList(castedList);
if (eventFound)
return true;
}
// Only fire events if control is enabled.
if (singleItem.Enabled)
{
// look for events.
}
}
return false;
}
Would be great if someone has some suggestions! Thank you!