Вы должны расширить класс Map, чтобы создать список Пинов для привязки.
public class BindableMap : Map {
public static readonly BindableProperty MapPinsProperty = BindableProperty.Create(
nameof(Pins),
typeof(ObservableCollection<Pin>),
typeof(BindableMap),
new ObservableCollection<Pin>(),
propertyChanged: (b, o, n) =>
{
var bindable = (BindableMap)b;
bindable.Pins.Clear();
var collection = (ObservableCollection<Pin>)n;
foreach (var item in collection)
bindable.Pins.Add(item);
collection.CollectionChanged += (sender, e) =>
{
Device.BeginInvokeOnMainThread(() =>
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
case NotifyCollectionChangedAction.Replace:
case NotifyCollectionChangedAction.Remove:
if (e.OldItems != null)
foreach (var item in e.OldItems)
bindable.Pins.Remove((Pin)item);
if (e.NewItems != null)
foreach (var item in e.NewItems)
bindable.Pins.Add((Pin)item);
break;
case NotifyCollectionChangedAction.Reset:
bindable.Pins.Clear();
break;
}
});
};
});
public IList<Pin> MapPins { get; set; }
}
Затем в вашей ViewModel
private ObservableCollection<Pin> _pinCollection = new ObservableCollection<Pin>();
public ObservableCollection<Pin> PinCollection { get { return _pinCollection; } set { _pinCollection = value; OnPropertyChanged(); } }
Чтобы добавить простой пин:
PinCollection.Add(new Pin() { Position = YourPosition, Type = PinType.Generic, Label ="ABCD" });
Теперь вы можете легко ссылаться на этот элемент управления с помощью этого XAML.
<local:BindableMap MapType="Street" MapPins="{Binding PinCollection}" />