I have a child window that has to be on top of another one which is the main. I don't want to put the child one as TopMost
since the user might want to check for data on other windows. In short the child has to follow that maximize/minimize events as the parent main one
Main minimize--->Child minimize
Main maximize--->Child maximize
To do that I have defined in the main:
this.StateChanged += MainWindow_StateChanged;
and in that
public static event EventHandler OnMainWindowStateChanged;
private void MainWindow_StateChanged(object sender, EventArgs e)
{
OnMainWindowStateChanged?.Invoke(sender,e);
}
The logic should be:
Main window main class ---> Main window engine class ----> child window
To put some names it:
public MainWindow()
{
this.StateChanged += MainWindow_StateChanged;
//call to the engine
m_Designer = new CWorkFlowEditor(this, App.IsDeployment, OnMainWindowStateChanged);
}
...
//In the engine:
public EventHandler OnMainWindowStateChanged;
public CWorkFlowEditor(object parent, bool IsDeployment, EventHandler _OnMainWindowStateChanged)
{
OnMainWindowStateChanged = _OnMainWindowStateChanged;
}
...
// Finally, when I want to create the final child window:
wndPluginConfigurator = new Window() {};
OnMainWindowStateChanged += MainWindow_StateChanged;
wndPluginConfigurator.ShowDialog();
}
private void MainWindow_StateChanged(object sender, EventArgs e)
{
Console.Beep();
}
So the fact is that this event is never called for the above OnMainWindowStateChanged event is always null. And that is for the OnMainWindowStateChanged is also always null.
Obviously if there is a better way to achieve the result and I'd be most grateful for the explanation
Thanks for helping
ADD: The MainWindow is not visible to the CWorkflowEditor. I have therefore tried to pass the EventHAndler with an interface but that didn't work either.
To achieve the following
Main minimize--->Child minimize
Main maximize--->Child maximize
While launching the Child window set the Owner with Main Window.
Means Window childwindow = new Window childwindow.Owner = MainWindow childwindow.Show()
There seems to be some issue passing your eventhandler around, but as the eventhandler is static surely it will be easier to do this instead:
MainWindow.OnMainWindowStateChanged += MainWindow_StateChanged;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.