Call a public MainWindow function from within a Page in WPF

Viewed 10189

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??

4 Answers

The following solution worked for me to call a MainWindow function from another page;

((MainWindow)System.Windows.Application.Current.MainWindow).FunctionName(params);
Related