在MainWindow
构造函数中,我正在注册一个事件处理程序:
public partial class MainWindow : Window, INotifyPropertyChanged
{
public MainWindow()
{
InitializeComponent();
pageViewDocText = new PageViewDocText();
framePageDocFieldDetail.Content = pageViewDocText;
pageViewDocText.NewPageIRPRO += new GabeLib.SearchCls.DocEventHandler(ViewIPRO);
}
protected void ViewIPRO(string IRPOlink) // ...
}
public partial class PageViewDocText : Page, INotifyPropertyChanged
{
public event GabeLib.SearchCls.DocEventHandler NewPageIRPRO;
private void btn_PageBreakNext(object sender, RoutedEventArgs e)
{
// this fires but NewPageIRPRO is null
if (NewPageIRPRO != null)
{
NewPageIRPRO("dummylink");
}
}
}
但在PageViewDocText
中,NewPageIRPRO
为空
我做错了什么?
从PageViewDocText
开始,我想致电MainWindow.ViewIPRO
。
此事件处理程序触发并注册在pageViewDocText.NewPageIRPRO + =
下面的行App.StaticGabeLib.Search.NewDocIRPRO += new GabeLib.SearchCls.DocEventHandler(ViewIPRO);
答案 0 :(得分:1)
看起来你正在调用来自另一个类(未列出)的事件,并且缺少一个委托。
试试这段代码:
public partial class MainWindow : Window, INotifyPropertyChanged
{
public MainWindow()
{
InitializeComponent();
pageViewDocText = new PageViewDocText();
framePageDocFieldDetail.Content = pageViewDocText;
pageViewDocText.PageBreakNext += new PageBreakNext(ViewIPRO);
}
protected void ViewIPRO(string IRPOlink) // ...
}
public partial class PageViewDocText : Page, INotifyPropertyChanged
{
public delegate void PageBreakNext(string IRPOlink);
public event PageBreakNext PageBreak;
private void btn_PageBreakNext(object sender, RoutedEventArgs e)
{
// this fires but NewPageIRPRO is null
if (PageBreak != null)
{
PageBreak("dummylink");
}
}
}