gpt4 book ai didi

c# - 事件处理程序为空

转载 作者:太空狗 更新时间:2023-10-29 23:46:20 24 4
gpt4 key购买 nike

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);

最佳答案

看起来您正在调用另一个类(未列出)的事件并且缺少委托(delegate)。

试试这段代码:

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");
}
}
}

关于c# - 事件处理程序为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18454132/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com