本文介绍了MarkerClick可以工作,但是InfoWindowClick不能打开ViewModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 13:43