以下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;
}
在onCreate
,把mViewModel.getLiveData().observe(this, new Observer<List<YOUR STUFF>>(){
和.observe
放在init()
方法,这对我有用