Sharing state between ViewModels

后端 未结 2 967
心在旅途
心在旅途 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:28

    TabControl is ItemsControl, so you shouldn't be shy to bind its ItemsSource to ListBox.SelectedITems.

    Obviously ViewModel for List should have a property that would produce ViewModel for Tabs:

    public TabViewModel ItemTabModel { get { ... } }
    

    And because TabControl is a bit funny, you'd need to add ItemContainerStyle to populate Content for TabControlItem, because the normal ItemTemplate for TableControl only affects headers for tabs.

提交回复
热议问题