Search code examples
xamarin.formsxamarin.forms.labsxlabs

Get instance of view registered in Xlabs.ViewFactory


Actually I am trying to structure my project in a clean MVVMV way. Unfortunately to this restriction I need to find a way to set pins to the map without the power DataBinding. One workaround could be to have the View in my ViewModel and set it directly. Right now I don't have any chance to get the registered view. Does it make sense to extend the XLabs.Forms.Mvvm.ViewFactory?

Before adding a new issue on GitHub, my hope is that there is a better solution to handle such restrictions. I always used MVVM in my (small) WPF projects.


Solution

  • No that doesn't make sense. Your best approach would be to extend the Maps class to make Pins an ObserverableCollection that is bindable.

    The new documentation format on the Xamarin site is rather difficult to read and does not provide the information you require at hand like it used to but I believe the Pins object is not bindable.

    Take a look at the Xamarin Forms Labs Github project to get an idea of how this can be done. The approach is defined particularly well in the ExtendedPicker classes (here the items are bound to an ObservableCollection).