Q:

Calling a method in one code behind from another code behind in WPF

What is the best way of calling a method that is in the code behind of a window from the code behind of another window? For example I have a method ShowSamples() in the code behind of my MainWindow, I have a separate window Window2, once the user clicks a Button on Window2 I want the ShowSamples() method in the code behind of MainWindow to be executed. How would I go about achieving this?
NOTE: The windows do not have a reference to each other, they do not inherit from a given class and do not have a parent-child relation ship, 2 completely separate windows in 1 application.

A:

If your trying to call a method on your current MainWindow, you can access the applications main window, and call its method using a cast. Assuming your MainWindow is called SamplesWindow, this should work:
((SamplesWindow)Application.Current.MainWindow).ShowSamples();

