Simple C# event args question
Im using WPF which has a Storyboard
cla开发者_高级运维ss that has a Completed
event.
I use it like so:
sb.Completed += AddControlToTaskbar;
private void AddControlToTaskbar(object sender, EventArgs args)
{
//...
}
How to I pass in the EventArgs
to my method? Its always null, and I need it to be a custom class
Thanks Mark
You don't pass the EventArgs
to your method, the framework which dispatches the event does that. A common way to handle this is to wrap up your AddControlToTaskbar
method in a class which stores the state, e.g.:
sb.Completed += new MyCustomClass(theStateYouNeedToStore).AddControlToTaskbar;
Your constructor stores the state.
class MyCustomClass<T> {
private T state;
public MyCustomClass(T state) {
this.state = state;
}
public void AddControlToTaskbar(object sender, EventArgs args) {
// Do what you need to do, you have access to your state via this.state.
}
}
精彩评论