用Caliburn Micro和WP7调用Map控件的方法 [英] Calling method of Map control with Caliburn Micro and WP7
问题描述
我的Windows Phone 7应用程序中有一个页面(视图),该页面使用Silverlight Map控件.
I have a page (view) in my Windows Phone 7 application that uses the Silverlight Map control.
我需要在控件上调用 SetView 方法,但是我想坚持在视图模型中保留功能的MVVM风格.
I need to call the SetView method on the control, but I'd like to stick to the MVVM style of keeping functionality in the view model.
我计划在单击应用程序栏按钮后调用此方法,因此我无法通过EventArgs参数访问地图.
I plan to call this method after clicking on an application bar button, so I don't have access to the Map via the EventArgs parameter.
做到这一点的最佳方法是什么?
What's the best way to do this?
推荐答案
我自己还没有使用过地图控件,但是这里面有一些想法:
I haven't worked with the map control myself, but here's a couple of ideas off of the top of my head:
-
您可以使用IEventAggregator发布事件,该事件可以订阅该视图并用于调用SetView.
You could publish an event using the IEventAggregator which the view could be subscribed to and use to call SetView.
您可以实现一个自定义IResult,该IResult使用ActionExecutionContext来获取视图,查找地图控件并在其上调用SetView.
You could implement a custom IResult which uses the ActionExecutionContext to get the view, find the map control and call SetView on it.
您可以在视图模型上实现IViewAware(或者,如果您从Screen继承,则可以重写OnViewLoaded),并通过通过界面与视图进行交互以调用SetView来遵循更高级的Controller Controller方法.
You could implement IViewAware on your view model (or override OnViewLoaded if you inherit from Screen) and follow a more Supervising Controller approach by interacting with the view through an interface to call SetView.
这篇关于用Caliburn Micro和WP7调用Map控件的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!