Portability suggestions - InitializeComponent and ConnectEvent
Posted: 18 Jan 2022, 22:58
I am looking at porting a substantial application from WPF to Noesis. I have some suggestions that I think would make this easier, and eliminate the need for NOESIS-specific code in the window setup (at least in simple cases).
1. Make InitializeComponent virtual for Window, so it only needs to be overridden in cases where the default it not enough. The default could be:
2. Provide a default implementation for ConnectEvent that does the appropriate reflection to automatically add the event handler method to the event, something like this:
1. Make InitializeComponent virtual for Window, so it only needs to be overridden in cases where the default it not enough. The default could be:
Code: Select all
protected virtual void InitializeComponent()
{
GUI.LoadComponent(this, this.GetType().Name + ".xaml");
}
Code: Select all
protected virtual bool ConnectEvent(object source, string eventName, string handlerName)
{
EventInfo eventInfo = source.GetType().GetEvent(eventName);
MethodInfo method = this.GetType().GetMethod(handlerName, BindingFlags.NonPublic | BindingFlags.Instance);
if (eventInfo != null && method != null)
{
System.Type tDelegate = eventInfo.EventHandlerType;
System.Delegate d = System.Delegate.CreateDelegate(tDelegate, this, method);
eventInfo.AddEventHandler(source, d);
return true;
}
return false;
}