开发者

How to pass info from control to event at Runtime

I'm creating b开发者_运维百科uttons by code inside a FlowLayoutPanel and I can't create a click event for each one of the created buttons. I need some help cause i'm stuck on this.


You can just subscribe to each button's Click event as you create them.

For example:

Button newButton = new Button();
// Setup button...
newButton.Click += this.ClickHandler;

Then, somewhere else:

private void ClickHandler(object sender, RoutedEventArgs e)
{
      // Do something here
}

The other, potentially more elegant, option would be to bind the Button's Command to an ICommand. You could also set it's CommandParameter in order to pass additional, button specific, information.


Here's the solution, Manage controls at Runtime.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜