5

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

但在 中PageViewDocTextNewPageIRPRO为空

我究竟做错了什么?
PageViewDocText,我想打电话MainWindow.ViewIPRO

此事件处理程序触发并注册 pageViewDocText.NewPageIRPRO += 下面的行

App.StaticGabeLib.Search.NewDocIRPRO += new GabeLib.SearchCls.DocEventHandler(ViewIPRO);
4

1 回答 1

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");
        }
    }
}
于 2013-08-27T03:39:03.287 回答