开发者

Pass information from one view model to another

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

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜