I have my WPF project set up as follows
In my MainWindow I have some tabs. A SearchJob tab and an Edit Job tab, the tabs display their own respective user controls
They all have their own ViewModels as their DataContext
MainWindow - MainWindowVM SearchJobs - SearchJobsVM EditJob - EditJobVM After I search for jobs I get a grid back that is bound to an ObservableCollection of Job objects
When I double click the results grid I want to make the Edit tab visible passing it's view model the id of the row I double clicked on
I also want to make some of the tabs in my MainWindow invisible. The tabs are bound to Visibility properties in my MainWindowVM
I am able to get the id of the row I double clicked on
My question is that from the SearchJobsVm I need to access bot the MainWindowVM to set the Visibility properties and also access the EditJobVM to set the ID
How do I access the DataContext (the view models) of the MainWindowVM and EditJobVM from SearcvhJobVM?
In Mainwindow I set the DataContext like so:-
<Window.DataContext> <vm:MainWindowViewModel /> </Window.DataContext> and the user controls are added in the xaml like so
<TabItem Header="Search"> <Grid Background="#FFE5E5E5"> <uc:SearchJobView></uc:SearchJobView> </Grid> </TabItem> My DataContext for SearchJobView is set like:-
<UserControl.DataContext> <vm:SearchJobViewModel/> </UserControl.DataContext> My DataContext for EditJobView is set like:-
<UserControl.DataContext> <vm:JobViewModel/> </UserControl.DataContext>