62

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 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});
}

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);
 }

UPDATE:

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;
 }
Michele La Ferla
  • 6,775
  • 11
  • 53
  • 79
casillas
  • 16,351
  • 19
  • 115
  • 215
  • 3
    any output on the log? Mvx is usually verbose, if a ViewModel can't be shown. – Sven-Michael Stübe Mar 13 '17 at 16:28
  • 1
    It writes on the output window `Showing ViewModel StudentViewModel` but nothing happens – casillas Mar 13 '17 at 16:42
  • 1
    It seems me to that there is an internal issue in the `ShowViewModel`, but I do not know how to handle? – casillas Mar 13 '17 at 19:16
  • 1
    Do you have a small demo project? – Sven-Michael Stübe Mar 13 '17 at 22:08
  • 1
    Not actually, at the moment. Is there any sample solution (`mvvmcross`) with couple of fragments that I could able to replicate the issue on it? – casillas Mar 13 '17 at 22:10
  • You could install this VS extension (disclaimer; I made it) to spin up a basic app for a repro: https://marketplace.visualstudio.com/items?itemName=LukePothier.MVXTemplates – Luke Pothier Mar 14 '17 at 08:13
  • Did you try to use the UIThread to call your ViewModel method? – hugo May 11 '17 at 23:38
  • mMap.SetOnInfoWindowClickListener(this); or mMap.InfoWindowClick += MMap_InfoWindowClick; Have you tried to do it inside OnMapReady(GoogleMap googleMap)? (and of course, IOnMapReadyCallback for your MapFragment ) – MoRRt Nov 06 '20 at 20:32
  • @casillas it does sound like something is wrong in your view. In the code-behind of that page, if you have InitializeComponent(). Wrap it in a try catch. The catch should hit if there is a problem with the UI and give you the error in question – Janwilx72 Sep 13 '21 at 08:01

1 Answers1

1

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

Peter
  • 437
  • 1
  • 4
  • 20