我应该如何使用 MVVM 移动 WPF 窗口? [英] How should I move a WPF Window using MVVM?

查看:36
本文介绍了我应该如何使用 MVVM 移动 WPF 窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这对 MVVM 模式来说可能有点矫枉过正,但对我来说是新的,我很想看看它是否可行.

This is probably overkill on the MVVM pattern but it's new to me and I'm interested to see if it is possible.

如果我附加到窗口的 MouseMove 事件并执行 DragMove,我可以移动一个无边框窗口.我可以通过 MVVM 中的其他方法实现这一点,还是应该接受将此代码添加到 Window 的代码隐藏中?

If I attach to the MouseMove event for a Window and do DragMove, I can move a bordeless window. Can I achieve this by some other method in MVVM or should I just accept adding this code to the Window's codebehind?

推荐答案

这是纯 UI 逻辑,不属于 ViewModel.您不想将其放在代码隐藏中的唯一原因是重复使用,而使用自定义 Window 派生控件可以更好地解决这一问题.

This is pure UI logic and doesn't belong in a ViewModel. The only reason you wouldn't want to put this in your code-behind would be for re-use and that is better solved with a custom Window derived control.

这篇关于我应该如何使用 MVVM 移动 WPF 窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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