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: 3690
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Chris
Posts: 4664
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

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
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3690
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Chris
Posts: 4664
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Event registration in class initializer

Post by Chris »

Hi Wolfgang,

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

XSharp Development Team test
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3690
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply