Silverlight 4 + MVVM + KeyDown event

你离开我真会死。 提交于 2019-12-04 07:39:41

Instead of using the EventTrigger, try to use the KeyTrigger and set the Source object to be the LayoutRoot.

Another option (which I think is better) is to let the ViewModel handle the position of the player. For example, have a property called PlayerTop and a property named PlayerLeft. Bind the PLayer's Canvas.Top and Canvas.Left property to these. When the user presses the Keys, a command is executed on the VM which updates these properties. This way the VM does not have to know what is moved, or how it is moved.

Does that make sense?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!