Sharing state between ViewModels

后端 未结 2 963
心在旅途
心在旅途 2021-01-06 14:27

I have two ViewModels that present the same Model to different Views. One presents the model as an item in a ListBox, the other presents it as a tab in a

2条回答
  •  有刺的猬
    2021-01-06 14:53

    Use a ViewModel.

    You've got a View that contains the two controls. Have a view model that will contain a list of ViewModels for the ListBox control to bind to. Also within this view model bind the listbox selection to a second list of viewmodels that the TabControl then also binds to.

    That way your listbox drives what the tab control shows without this information entering the model which should stay oblivious to the existence of the view.

提交回复
热议问题