我在Form
中定义了一个自定义事件,我想在一个不相关(即不是该表单的子项)UserControl
中进行订阅。
实际上,该事件从未在UserControl
中处理
我想念什么?
EventTopicNames.cs
public class EventTopicNames
{
public const string ApplicationClosing = "ApplicationClosing";
}
ShellApplication.cs
internal class ShellApplication : SmartClientSplashApplication<Microsoft.Practices.CompositeUI.WorkItem, ShellForm, SplashScreen>
{
base.Shell.FormClosing += this.Shell_FormClosing
private void Shell_FormClosing (object sender, System.Windows.Forms.FormClosingEventArgs formClosingEventArgs)
{
// notify all modules that the application is closing
Shell.OnApplicationClosing (new System.EventArgs());
}
}
ShellForm.cs
public partial class ShellForm : System.Windows.Forms.Form
[Microsoft.Practices.CompositeUI.EventBroker.EventPublication (Interface.Constants.EventTopicNames.ApplicationClosing, Microsoft.Practices.CompositeUI.EventBroker.PublicationScope.Global)]
public event System.EventHandler<System.EventArgs> ApplicationClosing;
protected internal virtual void OnApplicationClosing (System.EventArgs eventArgs)
{
if (this.ApplicationClosing != null)
{
this.ApplicationClosing (this, eventArgs);
}
}
UnrelatedUserControl.cs
public partial class UnrelatedUserControl : System.Windows.Forms.UserControl
{
[Microsoft.Practices.CompositeUI.Commands.CommandHandler(Infrastructure.Interface.Constants.EventTopicNames.ApplicationClosing)]
protected internal virtual void OnApplicationClosing(object sender, Infrastructure.Interface.EventArgs<Infrastructure.Interface.Aml.BusinessEntities.Project> eventArgs)
{
// do stuff but never called
}
}