How to call method of the main WPF window from the modal window?
(In fact I want to start some timer of the MainWindow.xaml.cs when I close some model window.)
Thank you!
What you can do is before opening your second window assign the main window as its owner, then from the modal window call the Owner property, cast it into a MainWindow object and you'll be able to execute the method.
// Code in main window
ModalWindow window = new ModalWindow();
window.Owner = this;
window.ShowDialog()
//Code on the modal window
var myObject = this.Owner as MainWindow;
myObject.MyMethod(); // Call your method here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With