从IValueConverter获取对ViewModel的引用 [英] Getting a reference to the ViewModel from an IValueConverter

查看:72
本文介绍了从IValueConverter获取对ViewModel的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种干净的和/或可接受的从IValueConverter引用ViewModel的标准方法,还是这打破了MVVM模式?基本上,我想基于ViewModel的其他属性在UI中转换绑定数据。我猜这与您如何从IValueConverter引用窗口/页面相同,因为对控件的引用没有传递到Convert / ConvertBack方法。

IValueConverter 。



签出关于 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆