我正在添加一些引腳到地圖,當用戶點擊這個引腳(實際上是引腳的內容),我想打開一個特定的頁面。我可以將參數傳遞給Xamarin中的Clicked事件嗎?
我想要做這樣的事情:
async void OnPinClicked(Places place)
{
await Navigation.PushAsync(new MyPage(place));
}
private void PopulateMap(List<Places> places)
{
for (int index = 0; index < places.Count; index++)
{
var pin = new Pin
{
Type = PinType.Place,
Position = new Position(places[index].Lat, places[index].Lon),
Label = places[index].Name,
Address = places[index].Address
};
pin.Clicked += (sender, ea) =>
{
Debug.WriteLine("Name: {0}", places[index].Name); // The app is crashing here (if I tap on a pin)
OnPinClicked(places[index]);
};
MyMap.Pins.Add(pin);
}
}
但我不知道這是否是可能的參數傳遞給OnPinClicked
功能。那可能嗎?如果不是,我能做些什麼來解決這個問題?
注意:我是Xamarin和C#的新手。
有關閉,請參閱我的回答後問EDIT部分 –