从IValueConverter获取对ViewModel的引用 [英] Getting a reference to the ViewModel from an IValueConverter
问题描述
是否有一种干净的和/或可接受的从IValueConverter引用ViewModel的标准方法,还是这打破了MVVM模式?基本上,我想基于ViewModel的其他属性在UI中转换绑定数据。我猜这与您如何从IValueConverter引用窗口/页面相同,因为对控件的引用没有传递到Convert / ConvertBack方法。
签出此关于 IValueConverters
的讨论使用MVVM。
Is there a clean and/or an accepted standard way of referring back to the ViewModel from an IValueConverter, or does that break the MVVM pattern? Basically, I want to convert bound data in the UI based on other properties of the ViewModel. I guess this is the same question as how do you refer back to the Window/Page from an IValueConverter since a reference to the control is not passed to the Convert/ConvertBack methods.
I would suggest adding a new property to the ViewModel that concatenates or combines the other properties in the ViewModel. This eliminates the need for an IValueConverter
all together.
Check out this discussion on IValueConverters
when using MVVM.
这篇关于从IValueConverter获取对ViewModel的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!