gpt4 book ai didi

wpf - 如何从 ViewModel 中的 View 获取动态值?

转载 作者:行者123 更新时间:2023-12-03 10:15:29 28 4
gpt4 key购买 nike

我遇到了一个场景,我需要根据 View 中的当前选择在 View 模型中做一些事情,但是根据 MVVM, 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com