开发者

Drawing on a canvas control in WPF using MVVM

I'm trying to convert my application to use the MVVM pattern. I currently have a custom canvas object that inherits form the standard canvas object, and overrides the OnRender event.

I am not quite sure how to convert this method to use the MVVM pattern.

Currently, I have an event wired up to different keypresses, to control the canvas and allows the user to scroll. I have gotten the event stuff wired up in MVVM using MvvmLight. I am just unsure about how when the Command fires in the view, that it updates the canvas. Currently there is a method that is called, that tells the control which direction the user has moved. (I basically pass i开发者_如何转开发n a location which is the index of an array).

Just not sure what I should be doing here.


I ended up going with DependencyProperties and using the DependencyProperties OnPropertyChanged Event Callback to update the graphics.


In our team we also have recently converted silverlight project to mvvm pattern. I don't know is it really required for this particular view to have a view model code to do canvas navigation stuff. If it is not I'd rather recommend to leave this code in view. Otherwise you can expose the

public Point CurrentCoordinate 

property and bind to it from view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜