Event registration in class initializer

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
wriedmann
Posts: 3462
Joined: Mon Nov 02, 2015 5:07 pm

Event registration in class initializer

Post 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
User avatar
Chris
Posts: 4207
Joined: Thu Oct 08, 2015 7:48 am

Event registration in class initializer

Post 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
User avatar
wriedmann
Posts: 3462
Joined: Mon Nov 02, 2015 5:07 pm

Event registration in class initializer

Post 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
User avatar
Chris
Posts: 4207
Joined: Thu Oct 08, 2015 7:48 am

Event registration in class initializer

Post by Chris »

Hi Wolfgang,

Agreed. Guess support (auto completion) for the old form should be completely removed, right?
User avatar
wriedmann
Posts: 3462
Joined: Mon Nov 02, 2015 5:07 pm

Event registration in class initializer

Post 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
Post Reply