Kiang Teng
Kiang Teng

Reputation: 1705

Pass information from one view model to another

alt text

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?

Upvotes: 5

Views: 393

Answers (2)

jbe
jbe

Reputation: 7031

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.

Upvotes: 1

decyclone
decyclone

Reputation: 30810

Have one ViewModel like :

  • ParentViewModel
    • ChildViewModel1
      • IsVisible
      • A Command that toggles ChildViewModel's IsVisible property
    • ChildViewModel2
      • IsVisible

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)

This should solve your problem.

Upvotes: 2

Related Questions