I have a WPF Application that has a main window and several pages that I navigate to like so:
e.g From one page to another I use:
NavigationService.Navigate(new MyPage1());
And from my main window to show a page I use:
_mainFrame.Navigate(new PageHome());
I have a public function on my MainWindow that I want to call from a within page.
How do I do this??
You shouldn't call the method directly.
What you should do is raise an event in your page and have the MainWindow subscribe to the event. That event handler can then call the method in question.
In PageHome:
public event EventHandler SomethingHappened;
private void MakeSomethingHappen(EventArgs e){
if(SomethingHappened != null){
SomethingHappened(this, e);
}
}
In MainWindow:
pageHome.SomethingHappened += new EventHandler(pageHome_SomethingHappened);
void pageHome_SomethingHappened(object sender, EventArgs e){
MyMethod();
}
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