View Issue Details

IDProjectCategoryView StatusLast Update
0002244NoesisGUIC# SDKpublic2025-06-05 11:26
Reporterasthomas Assigned Tojsantos  
PrioritynormalSeverityfeature 
Status assignedResolutionopen 
Product Version3.1.2 
Target Version3.2 
Summary0002244: Portability suggestions - InitializeComponent and ConnectEvent
Description

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:

        protected virtual void InitializeComponent()
        {
            GUI.LoadComponent(this, this.GetType().Name + ".xaml");
        }
  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:

        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;
        }
PlatformAny

Activities

jsantos

jsantos

2022-01-20 13:01

manager   ~0007751

We also have plans to add something similar to ConnectEvent but for x:Name items, something like ConnectVar.

If we are able to make this work for all platforms, the proposed solution in this ticket will allow us to leave InitializeComponent empty, without having to use an extra #ifdef for this.

I am excited about this :)

jsantos

jsantos

2022-03-07 19:24

manager   ~0007832

Thinking more about this, we could do the same in C++, just adding to the reflection each event and each named member. And then the reflection mechanism would connect them, following exactly the same implementation for both C# and C++.

Issue History

Date Modified Username Field Change
2022-01-19 15:11 asthomas New Issue
2022-01-19 15:11 asthomas Tag Attached: C#
2022-01-20 13:01 jsantos Note Added: 0007751
2022-01-20 13:01 jsantos Assigned To => jsantos
2022-01-20 13:01 jsantos Status new => assigned
2022-01-20 13:01 jsantos Target Version => 3.1
2022-03-07 19:24 jsantos Note Added: 0007832
2022-08-18 13:42 jsantos Target Version 3.1 => 3.2.0
2022-08-18 13:46 jsantos Additional Information Updated
2023-03-27 12:14 jsantos Target Version 3.2.0 => 3.2
2025-06-05 11:26 jsantos Description Updated