Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I move a WPF Window using MVVM?

Tags:

mvvm

wpf

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

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?

like image 347
Bill Jeeves Avatar asked Dec 12 '22 20:12

Bill Jeeves


2 Answers

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.

like image 145
John Bowen Avatar answered Dec 16 '22 16:12

John Bowen


Personally I think any solution using MVVM would not make this code any better. Also, this is typically something that's view related and hasn't got anything to do with the data you're displaying.

like image 21
Willem Meints Avatar answered Dec 16 '22 17:12

Willem Meints