问题描述
下面的MarkerClick
实现可以正常工作.我可以通过ShowViewModel
The following MarkerClick
implementation works, perfectly fine. I could able to open other View via 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
不会触发打开其他视图.
InfoWindowClick
does not trigger to open other 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
,它也没有打开View.
I even tried the SetOnInfoWindowClickListener
as follows, it also does not open the View.
mMap.SetOnInfoWindowClickListener(this);
public void OnInfoWindowClick(Marker marker)
{
ViewModel.MapInfoSelected(marker.Title);
}
更新:
它甚至命中了OnPause()
方法,但是如果我使用InfoWindowClick
事件,它仍然不会调用StudentViewModel
Init()方法
It even hits the OnPause()
method, but still it does not call StudentViewModel
Init() method if I use InfoWindowClick
event
public override void OnPause()
{
base.OnPause();
mMap.InfoWindowClick -= MMap_InfoWindowClick;
}
推荐答案
在onCreate
中,将mViewModel.getLiveData().observe(this, new Observer<List<YOUR STUFF>>(){
放入.observe
并放入init()
方法,对我来说这就是有效的方法
In onCreate
, put mViewModel.getLiveData().observe(this, new Observer<List<YOUR STUFF>>(){
and in the .observe
put the init()
method, that is what works for me
这篇关于MarkerClick可以工作,但是InfoWindowClick不能打开ViewModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!