我遇到一个场景,我需要根据 View 中当前的选择在 View 模型中做一些事情,但是根据MVVM, View 模型不应该知道 View 的存在,那么我怎样才能得到 View 中的动态选择?
最佳答案
来自Josh Smith's Article on MVVM
Unlike the Presenter in MVP, a ViewModel does not need a reference to a view. The view binds to properties on a ViewModel, which, in turn, exposes data contained in model objects and other state specific to the view.
因此,您可以在 ViewModel 中拥有一个属性并将其绑定(bind)到 ListView 的 SelectedItem。
关于wpf - 如何从ViewModel中的View获取动态值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2854876/