MarkerClick有效,但InfoWindowClick无法打开ViewModel

问题描述 投票:23回答:1

以下MarkerClick实现工作,非常好。我可以通过ShowViewModel打开其他视图

View.cs

mMap.MarkerClick += MMap_MarkerClick;

private void MMap_MarkerClick(object sender, GoogleMap.MarkerClickEventArgs e)
{
   ViewModel.MapInfoSelected(e.Marker.Title);
}

ViewModel.cs

public void MapInfoSelected(string name)
{
    ShowViewModel<StudentViewModel>(new { studentName = name});
}

InfoWindowClick不会触发打开其他View。

View.cs

mMap.InfoWindowClick += MMap_InfoWindowClick;

private void MMap_InfoWindowClick(object sender, GoogleMap.InfoWindowClickEventArgs e)
{
  ViewModel.MapInfoSelected(e.Marker.Title);
}

ViewModel.cs

public void MapInfoSelected(string name)
{
 // it hits here, but does not hit `StudentViewModel` Init() method, the app is frozen and do nothing
    ShowViewModel<StudentViewModel>(new { studentName = name});
}

我甚至尝试了SetOnInfoWindowClickListener如下,它也没有打开视图。

 mMap.SetOnInfoWindowClickListener(this);

 public void OnInfoWindowClick(Marker marker)
 {
     ViewModel.MapInfoSelected(marker.Title);
 }

更新:

它甚至击中了OnPause()方法,但如果我使用StudentViewModel事件,它仍然不会调用InfoWindowClick Init()方法

 public override void OnPause()
 {
   base.OnPause();
   mMap.InfoWindowClick -= MMap_InfoWindowClick;
 }
android google-maps xamarin xamarin.android mvvmcross
1个回答
0
投票

onCreate,把mViewModel.getLiveData().observe(this, new Observer<List<YOUR STUFF>>(){.observe放在init()方法,这对我有用

© www.soinside.com 2019 - 2024. All rights reserved.