WPF mvvm switch view

I have a WPF application. I need to have two views : a "configuration" view, and a "main" view... I need to use Prism to apply the MVVM pattern.

I found this question. I tried to use this code :

<Window.Resources>
    <DataTemplate DataType="{x:Type viewmodels:viewmodel1}" >
         <views:Usercontrol1/>
    </DataTemplate>

    <DataTemplate DataType="{x:Type viewmodels:viewmodel2}" >
        <views:Usercontrol2/>
    </DataTemplate>
</Window.Resources>

<Grid DataContext="{Binding currentviewmodel}"/>

I created a Mainwindow and a UserControl and ViewModel for each view.

It says to create a command to modify the currentviewmodel... But how can I do it ? In my "configuration" view I have a "Save" button, and in the Save command I need to switch the view...

I also found this tutorial but it's for mvvm light and I don't know how to modify "ViewModelBase" for Prism... and even if I could, this exemple have buttons in the MainWindow, but I need to switch the view from my "configuration" viewmodel...

Maybe there is a better way to do it...

Edit : still looking for a simple navigation example with mvvm and prism...

链接地址: http://www.djcxy.com/p/56184.html

上一篇: 通过MVVM LIGHT(WPF)导航UserControl

下一篇: WPF mvvm切换视图