C# Google Maps Bindings Xamarin.Forms-使用BindingPinsBehavior时地图上不显示PIN

C# Google Maps Bindings Xamarin.Forms-使用BindingPinsBehavior时地图上不显示PIN,c#,xaml,xamarin,xamarin.forms,maps,C#,Xaml,Xamarin,Xamarin.forms,Maps,Kia ora StackOverFlow 我正在创建一个GoogleMaps页面,其中有许多绑定(我使用了GoogleMaps绑定)。这种绑定的一个示例是pin绑定-如下所示: XAML: 现在-问题是-我已经按预期设置了BindingContext,但是在地图上找不到pin 重要的是我可以在地图上看到PIN,因为我正在制作一个应用程序,用户需要在其中查看事件/聚会的位置。我还需要一个MVVM方法的解决方案 (使用Android棒棒糖) 它应该在地图上的什么位置 图像 这是我的问题 谢谢,

Kia ora StackOverFlow

我正在创建一个GoogleMaps页面,其中有许多绑定(我使用了GoogleMaps绑定)。这种绑定的一个示例是pin绑定-如下所示:

XAML:

现在-问题是-我已经按预期设置了BindingContext,但是在地图上找不到pin

重要的是我可以在地图上看到PIN,因为我正在制作一个应用程序,用户需要在其中查看事件/聚会的位置。我还需要一个MVVM方法的解决方案

(使用Android棒棒糖)

它应该在地图上的什么位置

图像

这是我的问题

谢谢,

起拍到ra

祝你度过愉快的一天

编辑:感谢Leo Zhu,他解决了我的问题-我现在正在寻找基于MVVM的解决方案,但无论如何,谢谢你

我尝试过的事情 结果 尝试使用默认映射项模板设置接点的绑定。 仍然没有工作或显示在地图上 尝试在将项添加到可观察集合后调用OnPropertyChanged 地图上仍然没有显示这个别针 尝试使用管脚而不是管脚的可观察集合 地图上仍然看不到别针 尝试将映射本身的BindingContext设置为MainPageViewModel 但别针仍然不见踪影 尝试使用Google地图绑定NuGet包的早期更新 不过——你猜对了——我看不到别针
我遇到了同样的问题,一个解决方法不是在viewModel的构造函数中添加
Pin
,而是在
page.xaml.cs
中添加,如下所示:

<maps:Map VerticalOptions="FillAndExpand" x:Name = "myMap"
              MyLocationEnabled="True">
  <maps:Map.Behaviors>
     <bindings:BindingPinsBehavior Value="{Binding Pins}" />
  </maps:Map.Behaviors>
</maps:Map>

public MapPage()
    {
        InitializeComponent();
        myMap.Pins.Add(new Pin
        {
            Label = $"Pin1",
            Position = new Position(78, 77)
        });
    }

公共地图页()
{
初始化组件();
myMap.Pins.Add(新Pin)
{
标签=$“Pin1”,
位置=新位置(78,77)
});
}

我遇到了同样的问题,一个解决方法不是在viewModel的构造函数中添加
Pin
,而是在
page.xaml.cs
中,如下所示:

<maps:Map VerticalOptions="FillAndExpand" x:Name = "myMap"
              MyLocationEnabled="True">
  <maps:Map.Behaviors>
     <bindings:BindingPinsBehavior Value="{Binding Pins}" />
  </maps:Map.Behaviors>
</maps:Map>

public MapPage()
    {
        InitializeComponent();
        myMap.Pins.Add(new Pin
        {
            Label = $"Pin1",
            Position = new Position(78, 77)
        });
    }

公共地图页()
{
初始化组件();
myMap.Pins.Add(新Pin)
{
标签=$“Pin1”,
位置=新位置(78,77)
});
}

请不要初始化ObservableCollection引脚

MainPageViewModel.cs

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms.GoogleMaps;
using Xamarin.Forms.GoogleMaps.Bindings;

namespace standard.ViewModels
{
    public class MainPageViewModel : BaseViewModel
    {

       public ObservableCollection<Pin> Pins { get; set; }

        public MainPageViewModel()
        {
            
        }

        internal void AddPins()
        {
            Pins?.Add(new Pin()
            {
                Label = $"Pin1",
                Position = new Position(78, 77)
            });
        }
    }
}

请不要初始化ObservableCollection引脚

MainPageViewModel.cs

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms.GoogleMaps;
using Xamarin.Forms.GoogleMaps.Bindings;

namespace standard.ViewModels
{
    public class MainPageViewModel : BaseViewModel
    {

       public ObservableCollection<Pin> Pins { get; set; }

        public MainPageViewModel()
        {
            
        }

        internal void AddPins()
        {
            Pins?.Add(new Pin()
            {
                Label = $"Pin1",
                Position = new Position(78, 77)
            });
        }
    }
}


你知道78,77在地图上的什么地方吗?提示-它不在你屏幕上的任何地方是的@Jason我搜索了整个地图,但它不在那里。是否要添加其他内容?关于
RaisePropertyChanged(nameof(Pins))添加一个pin后?我明天会尝试-谢谢@Shaw(因为我使用的是'CallerMemberName'属性,所以不需要nameof)或在中添加CollectionChaged事件。无论如何,将项目添加到集合不会引发集合的属性更改。您知道78,77在地图上的位置吗?提示-它不在你屏幕上的任何地方是的@Jason我搜索了整个地图,但它不在那里。是否要添加其他内容?关于
RaisePropertyChanged(nameof(Pins))添加一个pin后?我明天会尝试-谢谢@Shaw(因为我使用的是'CallerMemberName'属性,所以不需要nameof)或在中添加CollectionChaged事件。无论如何,向集合中添加项目不会引发集合的属性更改。是的,但这将打破我正在制作的应用程序所需的MVVM模式。如果你找不到更好的方法来使用MVVM,你可以先使用这个解决方法。好的,谢谢你的回答-如果赏金后我没有得到解决方案,那么你将是被选中的答案。如果你找到了解决方案,请让我知道。是的,但这将打破我制作的应用程序的MVVM模式。如果你找不到更好的方法使用MVVM,您可以先使用此解决方法。好的,谢谢您的回答-如果在赏金之后我没有得到解决方案,那么您将是被选中的答案。如果您找到了解决方案,请让我知道。非常感谢@jai提供的解决方案-效果非常好!(在5小时内,我可以授予声誉)非常感谢@jai提供的解决方案-它工作得非常好!(在5小时内,我可以授予声誉)
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms.GoogleMaps;
using Xamarin.Forms.GoogleMaps.Bindings;

namespace standard.ViewModels
{
    public class MainPageViewModel : BaseViewModel
    {

       public ObservableCollection<Pin> Pins { get; set; }

        public MainPageViewModel()
        {
            
        }

        internal void AddPins()
        {
            Pins?.Add(new Pin()
            {
                Label = $"Pin1",
                Position = new Position(78, 77)
            });
        }
    }
}
using standard.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.GoogleMaps;

namespace standard
{
    public partial class MainPage : ContentPage
    {
        public MainPageViewModel MainPageViewModel;
        public MainPage()
        {
            MainPageViewModel = new MainPageViewModel();
            this.BindingContext = MainPageViewModel;
            InitializeComponent();
            MainPageViewModel.AddPins();
            
        }
    }
}