Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event Handler Null

In the MainWindow constructor, I am registering an event handler:

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

But in PageViewDocText, NewPageIRPRO is null

What am I doing wrong?
From PageViewDocText, I want to call MainWindow.ViewIPRO.

This event handler fires and is registered the line below pageViewDocText.NewPageIRPRO +=

App.StaticGabeLib.Search.NewDocIRPRO += new GabeLib.SearchCls.DocEventHandler(ViewIPRO);
like image 569
paparazzo Avatar asked Nov 12 '22 23:11

paparazzo


1 Answers

Looks like you are calling an event from another class (not listed) and there is a missing delegate.

Try this code:

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");
        }
    }
}
like image 175
sharpguru Avatar answered Nov 14 '22 22:11

sharpguru