I am trying to implement a Master detail view in WPF MVVM.
In my viewmodel I have a observable collection of "Causes". Each Cause has an observable collection of "Solutions".
I bound an editable Datagrid to the Causes and it is working fine. But when a user selects a row in the DataGrid I want to allow the user to see its associated solutions in the TabControl.
How should I go about doing this? Should I create a property CurrentCause in the Viewmodel and bind it to the SelectedItem. In the TabControl can I bind to CurrentCause.Solutions.
Will this be an optimal approach? Please advise. Thanks!!
I would bind your DataGrid to a list of Causes, the SelectedItem to CurrentCause in your Model and the TabControl to Solutions. Then you have everything nicely tied up in your MVVM.
You could bind the
ItemsSource
of the TabControl to be theSelectedItem
of the DataGrid using element binding.You can set IsSynchronizedWithCurrentItem to True and do something like this.