我正在使用最新的 Phone 7 RTM 工具(今天下载,2010 年 10 月 7 日)。
我想在这里做一件简单的事情:
当用户点击一次 在 map 控件上,我想在那里放一个图钉。
另外,我想保持 map 控件的常规内置行为( 点击两次 进行缩放)。
(如果不可能同时保留这两种行为,那么也许可以在 map 上长按以放置图钉)。
在尝试解决此问题时,我遇到了对 Phone7 控制图所做更改的文档:
http://msdn.microsoft.com/en-us/library/ff955762.aspx
然后我看到了新类(class) MapInputEventArgs ,它有一个 ViewportPoint 成员。
查看 上的代码示例时常规 SilverLight map 控件 我看到了这样的事情:
private void OnMouseClick(object sender, MapMouseEventArgs e)
{
Point clickLocation = e.ViewportPoint;
Location location = x_Map.ViewportPointToLocation(clickLocation);
Pushpin pushpin = new Pushpin();
m_PushpinLayer.AddChild(pushpin, new Location(latitude, longitude));
}
但是在Phone7的情况下,我找不到合适的事件处理程序,也找不到谁在 map 控件中使用了MapInputEventArgs。
在谷歌上搜索它只得到 1 个结果!!
那么,“点击一次”的适当事件在哪里,以及在触发此事件后如何获得 ViewportPoint?
提前致谢。
最佳答案
如果您仍然遇到问题,请弄清楚这一点。
MouseLeftButtonUp 和 MouseLeftButtonDown 事件有一个 GetPosition 方法,它将返回您要查找的点
private void MapMain_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Point p = e.GetPosition(this.MapMain);
GeoCoordinate geo = new GeoCoordinate();
geo = MapMain.ViewportPointToLocation(p);
MapMain.ZoomLevel = 17;
MapMain.Center = geo;
//---create a new pushpin---
Pushpin pin = new Pushpin();
//---set the location for the pushpin---
pin.Location = geo;
//---add the pushpin to the map---
MapMain.Children.Add(pin);
}
关于windows-phone-7 - 电话 7 Bing map 控件 - 点击时添加图钉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3880497/