xsharp.eu • Event registration in class initializer
Page 1 of 1

Event registration in class initializer

Posted: Wed Aug 16, 2023 9:04 pm
by wriedmann
Hi Robert,
this code is valid (and I'm using it frequently):

Code: Select all

oMenuItem := MenuItem{}{ Header := "Exit", Command := ExitCommand}
but unfortunately this code does not compiles:

Code: Select all

oMenuItem := MenuItem{}{ Header := "Exit", Click += FileExit }
It gives several error messages, like

Code: Select all

error XS1922: Cannot initialize type 'System.Windows.Controls.MenuItem' with a collection initializer because it does not implement 'System.Collections.IEnumerable'
Could it be possible to make this also work, please?
Thank you very much!
Wolfgang

Event registration in class initializer

Posted: Thu Aug 17, 2023 5:25 am
by Chris
Hi Wolfgang,

Unfortunately this is not supported in c# either (which X# uses as a backend):

https://github.com/dotnet/csharplang/discussions/307

Event registration in class initializer

Posted: Thu Aug 17, 2023 8:27 am
by wriedmann
Hi Chris,
thank you very much!
Wolfgang
P.S. maybe you could have a look to the code completion for the events in XIDE as it seems to support only the long form and not the short form

Event registration in class initializer

Posted: Thu Aug 17, 2023 2:29 pm
by Chris
Hi Wolfgang,

Agreed. Guess support (auto completion) for the old form should be completely removed, right?

Event registration in class initializer

Posted: Thu Aug 17, 2023 7:48 pm
by wriedmann
Hi Chris,
sorry for answering late, but currently I'm on holiday.
Yes, I think removing the old form would be the best option. I cannot immagine someone that prefers the old form over the new one.
Wolfgang