LINQPad.Controls Event sender got null
// Winform
var button = new System.Windows.Forms.Button {
Text = "Copy",
Location = new Point(150, 100),
Size = new Size(100, 30)
};
button.Click += (sender, e) => {
//here can got button object
var buttonSender = (sender as System.Windows.Forms.Button);
};
// LINQPad.Controls
var button = new LINQPad.Controls.Button("Copy").Dump();
button.Click += (sender, e) => {
// this got null
var buttonSender = (sender as LINQPad.Controls.Button);
};
Why transform sender to LINQPad.Controls always got null
Comments
-
var button = new LINQPad.Controls.Button("Copy").Dump(); button.Click += (sender, e) => { var buttonSender = sender.GetType().Dump(); };LINQPad.Controls.Core.HtmlElement -
Good spot. This is not ideal behavior - LINQPad should supply the button as the sender, not the HtmlElement. Fixing it is a breaking change, though, so it might have to wait for LINQPad 9.
-
@JoeAlbahari said:
Good spot. This is not ideal behavior - LINQPad should supply the button as the sender, not the HtmlElement. Fixing it is a breaking change, though, so it might have to wait for LINQPad 9.Is this issue fixed in LINQPad 9?
-
It didn't pass review because that change that would still break existing scripts.
Is there any reason that you need this? The sender parameter was useful in the C# 1 days, before the language had closures. But now we can do this (which is also type-safe):
var button = new LINQPad.Controls.Button("Copy").Dump(); button.Click += (sender, e) => { var buttonSender = button; };
