【发布时间】:2015-03-15 00:31:02
【问题描述】:
我需要在使用 Xamarin Forms 开发的项目中使用自定义渲染器实现地图,我是这样做的:
public class MyMap : Map
{
public MyMap ():base(){ }
}
MapView(Xamarin 表单):
public class MapView:ContentPage
{
List<Filiale> list=jM.ReadData ();
MyMap myMap = new MyMap (//I'd like to pass list here);
var stack = new StackLayout ();
myMap.VerticalOptions = LayoutOptions.FillAndExpand;
myMap.HorizontalOptions = LayoutOptions.FillAndExpand;
stack.Children.Add (myMap);
Content = stack;
}
MapRenderer (Xamarin iOS):
[assembly: ExportRenderer (typeof (MyMap), typeof (MapiOS))]
namespace App.iOS
{
public class MapiOS : MapRenderer
{
private MKMapView NativeMap { get { return (this.NativeView as MapRenderer).Control as MKMapView; } }
public MapiOS ():base()
{
}
protected override void OnElementChanged (ElementChangedEventArgs<View> e)
{
base.OnElementChanged (e);
MyMapDelegate myMapDelegate = new MyMapDelegate ();
NativeMap.Delegate = myMapDelegate;
NativeMap.AddAnnotation(new MKPointAnnotation (){
Title=list[0].nome,
Coordinate = new CLLocationCoordinate2D (42.364260, -71.120824)
});
}
}
在myMapDelegate 类中,我还处理了点击 Pins 后显示的按钮的点击,如下所示:
public override void CalloutAccessoryControlTapped (MKMapView mapView, MKAnnotationView view, UIControl control){
//Call new Page
}
现在,当单击此按钮时,我想返回 Xamarin Forms 并使用它创建一个新页面。我该怎么做?另外,当我创建 MyMap 对象时如何传递一些对象?
【问题讨论】:
-
只是为了理解。您想传递给
MyMap的列表:这是位置列表吗?当你点击一个图钉时,应该在你的MapView上调用一些方法 -
列表为Fiiale类型示例中声明的列表。并且调用的方法在MyMapDelegate上,CalloutAccessoryTapped
标签: c# xamarin xamarin.forms