MarkerClick 有效,但 InfoWindowClick 无法打开 ViewModel [英] MarkerClick works but InfoWindowClick does not open ViewModel

查看:14
本文介绍了MarkerClick 有效,但 InfoWindowClick 无法打开 ViewModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下 MarkerClick 实现工作,非常好.我可以通过 ShowViewModel

The following MarkerClick implementation works, perfectly fine. I could be able to open other Views 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 如下,它也没有打开视图.

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>(){ 并在 .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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆