我有问题。我有一个简短的客户端列表,对于每个客户端,我想显示一个图钉和弹出窗口,单击信息窗口后将显示该窗口。但是,我不知道如何连接。
部分代码:
List<Client> lstClients = new List<Client>
{
new Client(1, "Firma 1", "Wspólna 10", "123-123-23-23", "F1", true),
new Client(2, "Firma 2", "Marszałkowska", "456-456-56-45", "F2", false),
new Client(3, "Firma 3", "Jerozolimskie 57", "789-789-89-78", "F3", true),
new Client(4, "Firma 4", "Koszykowa 10", "234-423-43-23", "F4", false)
};
foreach (Client client in lstClients)
{
var geoadres = client.Address;
var locations = await Geocoding.GetLocationsAsync(client.Address);
var location = locations?.FirstOrDefault();
ListPin = new Pin
{
Type = PinType.Place,
Label = client.FirmName,
Address = client.Address,
Position = (new Position(location.Latitude, location.Longitude)),
Rotation = 33.3f,
Tag = client.Tag
};
map.Pins.Add(ListPin);
}
void InfoWindow_Clicked(object sender, InfoWindowClickedEventArgs e)
{
PopupNavigation.Instance.PushAsync(new ShowPopup());
}
我将不胜感激。
答案 0 :(得分:0)
通过单击图钉需要显示弹出窗口,您可以像这样实现;
foreach (Client client in lstClients)
{
var geoadres = client.Address;
var locations = await Geocoding.GetLocationsAsync(client.Address);
var location = locations?.FirstOrDefault();
ListPin = new Pin
{
Type = PinType.Place,
Label = client.FirmName,
Address = client.Address,
Position = (new Position(location.Latitude, location.Longitude)),
Rotation = 33.3f,
Tag = client.Tag
};
map.Pins.Add(ListPin);
// tap event from map pinview -> Callout action
map.Pins[i].Clicked += (sender, e) =>
{
System.Diagnostics.Debug.WriteLine(((Pin)sender).Type);
DisplayAlert(((Pin)sender).Label, ((Pin)sender).Address, "OK");
};
}
在for循环中添加代码