I'm working on a project in WPF-MVVM where I have a Main Window that contains a Tab Control with two tabs. Each of these tabs has a button on it.
In this project, there are 3 different View Models, one for the Main Window and one for each of the tabs. When one of the buttons is pressed, I would like the "parent" view model (the View Model for the Main Window) to perform some action, such as closing the application.
What is the proper way to go about having the View Model for the Tabs ask the Main View Model to perform this action?
Screenshot of Application
Code on Pastebin
Note: I am not using any sort of framework such as MVVM Light or Prism.
You could access the parents DataContext by using a relative binding like this:
Binding="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Window}}, Path=DataContext.AllowItemCommand}"
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