I
I
Igor Dmitrashko2020-02-27 18:53:28
WPF
Igor Dmitrashko, 2020-02-27 18:53:28

Guys, why is the event null?

Sori that a lot of information))
There is a MainWindows form
It has a button that calls the AddContent Form

private void ButtonAddSpending_Click(object sender, RoutedEventArgs e) {          
            AddContent addContent = new AddContent();
            addContent.Owner = this;
            addContent.ShowDialog();
        }

The AddContent form has an event when the form is called, in the constructor I subscribe to the event. here is ButtonAddContent_Click itselfpublic event EventHandler EventAddContent;

buttonAddContent.Click += ButtonAddContent_Click;

private void ButtonAddContent_Click(object sender, RoutedEventArgs e) {
            EventAddContent?.Invoke(this, EventArgs.Empty);
            this.Activate();
            buttonAddContent.IsEnabled = false;
        }


There is a class that controls all movements in the application
class MainPresenter
{
private readonly IAddContentPresenter _addContent;
in the constructor in the constructor I pass the interface in which there is this event.
(Form implements this interface)

public MainPresenter( IAddContentPresenter addContent) {           
            _addContent = addContent;
            _addContent.EventAddContent += View_AddContent;
        }

this class already has a method that implements pressing

private void View_AddContent(object sender, EventArgs e) { //Метод записывает данные в БД
            _manager.SetDBHistories(_history);
        }

Class constructor called in MainWindow
event not working!
in the debugger the event shows
null
 EventAddContent?.Invoke(this, EventArgs.Empty);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question