Should a ViewModel in MVVM reference the View?

后端 未结 4 475
生来不讨喜
生来不讨喜 2020-12-10 03:27

In the MVVM (Model-View-ViewModel) pattern should the ViewModel reference the view. I would think that it should not. But how should the following scenario be handeled? I ha

4条回答
  •  时光说笑
    2020-12-10 04:28

    One of us is missing something obvious. Your tab control is an ItemsControl. You should bind the ItemsSource of your tab control to an ovservable collection in your view model. When you handle the command in your view model to add a tab, you simply add a new element to this collection and, voila, you've added a new tab to the control.

提交回复
热议问题