Portability suggestions - InitializeComponent and ConnectEvent
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;
}
Re: Portability suggestions - InitializeComponent and ConnectEvent
These are super good ideas! I think we tried something similar long time ago but as far as I remember reflection was not working as expected for AOT platforms (iOS, Xbox...). Could you please create a ticket about this to check again? Thank you!
Re: Portability suggestions - InitializeComponent and ConnectEvent
I have added a ticket.
Incidentally, almost the same effect can be achieved by creating a derived class from Window, and then placing those two functions in that class. When porting from existing WPF code that class can be referenced with a "using" statement.
Since all WPF files need to have boilerplate changes to their using statements anyway, this limits the NOESIS-specific code to just one place.
Incidentally, almost the same effect can be achieved by creating a derived class from Window, and then placing those two functions in that class. When porting from existing WPF code that class can be referenced with a "using" statement.
Code: Select all
#if NOESIS
using Window = MyNamespace.MyDerivedWindow;
#endif
Re: Portability suggestions - InitializeComponent and ConnectEvent
Thanks for the ticket (#2244)
Who is online
Users browsing this forum: No registered users and 44 guests