如何使用MVVM在没有代码的情况下使用ManipulationDelta? [英] How do I handel ManipulationDelta Without Code Behind using MVVM?

查看:94
本文介绍了如何使用MVVM在没有代码的情况下使用ManipulationDelta?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个触摸屏应用程序,我知道我应该避免在后面的代码中添加代码。这导致了如何在视图模型中处理ManipulaitonDelta的问题。我不知道如何做到这一点,我希望有人可以帮助我。



谢谢!

I am building a touch-screen application, and I know I should avoid adding code to the code behind. Which leads to the question of how handle ManipulaitonDelta in the View Model. I have no idea how this can be done, and I am hoping someone can help me out.

Thanks!

推荐答案

避免代码隐藏不是一个普遍的事实,无论上下文如何都需要始终应用,它是否适用于您的情况?



当人们谈论避免代码背后的代码通常是指避免将非UI特定逻辑放入控件后面的代码中,因为这会将UI紧密耦合到应用程序逻辑的其余部分。您不希望后面的代码知道并直接修改您的业务实体(例如客户订单 class),在这种情况下,你需要一个视图模型通过从模型中抽象视图来解耦UI。 />


但是如果你正在构建一个UI控件的东西(我怀疑你的问题),那么在很多情况下完全可以依赖代码来代替代码是某种与控件的行为紧密相关的东西而不是某些应用程序逻辑。



考虑WPF类,如 Button 网格,这些类不受视图模型的支持,但仍然有很多代码,因为该代码是特定于控件的,而不是应用程序特定逻辑。



希望这会有所帮助,

Fredrik
Avoiding code behind is not a universal truth that needs to always be applied regardless of context, does it apply in your case?

When people talk about avoiding code behind they usually refer to avoiding putting non UI specific logic into the code behind of a control as this couples the UI to tightly to the rest of the application logic. You don't want the code behind to be aware of and directly modify your business entities (such as a Customer or Order class), in such cases you'll want a view model de-coupling the UI by abstracting the view from the model.

But if you're building something that's a UI control (as I suspect from your question), then it is perfectly Ok in many cases to rely on code behind if the code is something that's tightly bound to the behaviour of the control rather than some application logic.

Consider WPF classes like Button or Grid, these classes aren't backed by view models but still have a lot of code behind because that code is control specific, not application logic specific.

Hope this helps,
Fredrik


这篇关于如何使用MVVM在没有代码的情况下使用ManipulationDelta?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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