MarkerClick有效,但InfoWindowClick无法打开ViewModel

时间:2017-03-10 22:26:29

标签: android google-maps xamarin xamarin.android mvvmcross

以下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.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;
 }

1 个答案:

答案 0 :(得分:0)

onCreate中, 将mViewModel.getLiveData().observe(this, new Observer<List<YOUR STUFF>>(){放入.observe中并将init()方法放入,这对我来说是有效的