Pass information from one view model to another
I am using the M-V-VM architectural pattern.
I want my program to have two views, View A and View B. I start the program with View A. View B is shown by the program开发者_开发知识库 when I double click an item in View A.
How should I structure my program such that I can achieve this?
Have one ViewModel like :
- ParentViewModel
- ChildViewModel1
- IsVisible
- A Command that toggles ChildViewModel's IsVisible property
- ChildViewModel2
- IsVisible
- ChildViewModel1
and View like :
- ParentView
- ViewPart1
- Visibility bound to ChildViewModel1.IsVisible (use BooleanToVisibilityConverter)
- A button bound to Command that toggles Visibility
- ViewPart2
- Visibility bound to ChildViewModel1.IsVisible (use BooleanToVisibilityConverter)
- ViewPart1
This should solve your problem.
You might be interested in the BookLibrary sample application of the WPF Application Framework (WAF). It shows a master/detail view with two separate Views and two separate ViewModels. Additionally, it has a modal dialog inclusive an own ViewModel for the "Lend To" operation which is connected to the selected book.
精彩评论