1
votes

I am going to try my best to explain the problem in detail.

I am using WPF, MVVM and PRISM. Here is the structure of the app:


CONTAINER

User control containing a toolbar

----------          LEFT PANE USER CONTROL              
right pane
user control
----------

---------------------------------------------------------------

The Container is a Shell which host the look of the application. The Shell also contains many different user controls like User user control, Role user control, Categories user control. All of the controls are collapsed.

The toolbar has options like Save, Edit, Delete. When the user selects the Edit option from the toolbar then I use the WPF commands to call the Edit method on my ViewModel as shown below:

 private void Edit(UserViewModel userViewModel)
        {
            // load the edit page            

        }

The toolbar.Datacontext is set dynamically to the datacontext of the user control which is a viewmodel. So, the same toolbar can be used with different context to invoke commands on different viewmodels.

At this point I already get the correct UserviewModel passed in the Edit method. This is all fine! But now! I need to update the details pane to reflect the EditView. How can I do that? All the controls are embedded in the Shell.xaml file collapsed. Also the ViewModels are in a separate assembly and Shell is in a separate assembly.

This is where I need help! How can the viewModel who has no idea about the Shell since (Shell references the ViewModel assembly not the other way around) can inject an EditView into the Shell details pane.

2
how do you inject your views to the details panel? via data template, via region manager, or directly setting as a content of the details panel? appreciated if you could post a basic xaml for the container.pushpraj

2 Answers

1
votes

You can use the CommandParameter property bound to what you want to pass in.

<Button Content="Edit" Command="{Binding Path=EditCommand}" CommandParameter="{Binding SelectedItem, ElementName=datagrid}" />

Where datagrid is the Datagrid you mentioned.

0
votes

Go in your CONTAINER xaml and write

<CONTAINER.Resources>
    <DataTemplate DataType="{x:Type vm:UserViewModelVM}">
        <!--if your View is a separat Usercontrol-->
        <vw:UsertV />
        <!--else insert your UsertV xaml-->
    </DataTemplate>
</CONTAINER.Resources>

this xaml tells your app that if a UserViewModelVM is displayed directly it has to wrap it in your DataTemplate

now your go to your LEFT PANE USER CONTROL

<LEFT PANE USER CONTROL Content={Binding yourVMProperty}
                        DataContextContent={Binding yourVMProperty}/>

to expose the UserViewModelVM we bind it as Content and now it should work fine

also do not forget to RaisPropertyChanged and remove your collapsed because there is no need to hide it anymore :)

Ask me if you need further explanations.