当使用值转换器在MVVM应用程序吗?转换器、应用程序、MVVM

2023-09-03 04:33:33 作者:傾旎

如果一个使用MVVM设计模式实现一个WPF应用程序,有没有在其中使用值转换器的任何情况吗?在我看来,这个值转换器做同样的东西视图模型确实太少,这是preparing数据视图。

If one is implementing a WPF application using the MVVM design pattern, is there any situation in which to use value converters? It seems to me that value converters do exactly the same what the view model does too, that is preparing data for the view.

那么,有没有一些好的用途值转换器?

So, are there some good uses for value converters?

最好的问候 奥利弗Hanappi

Best Regards Oliver Hanappi

推荐答案

价值转换器方便的逻辑状态转化为可视状态是只与用户界面。一个BooleanToVisibility转换器,例如,有其在MVVM应用程序的地方。

Value converters are handy to translate logical states into visual states that are only relevant for the UI. A BooleanToVisibility converter, for example, has its place in a MVVM application.

不过,我绝不会建议使用转换器来执行任何复杂的转换与各种输入参数或调用任何业务逻辑的实现。这是虚拟的东西。

However, I would never recommend to use converters to perform any complex conversion with various input parameters or to call any business logic in their implementation. That's VM stuff.