We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Binding observable collection of custom markers

Hello syncfusion team,

I'm trying to bind a collection of custom markers to the Markers property of the SfMaps.

But it throws me an error :

 Binding: System.Collections.ObjectModel.ObservableCollection`1[Project.Core.Models.WeatherMarker] can not be converted to type 'System.Collections.ObjectModel.ObservableCollection`1[Syncfusion.SfMaps.XForms.MapMarker]' 
Well, I don't understand because using  the same marker class but w/o binding works. Is it bindable ? 

Marker class is pretty simple : 

   public class WeatherMarker : MapMarker
        public string LottieAnimation { get; set; }

    private ObservableCollection _weatherMarkers;
        public ObservableCollection WeatherMarkers
            get => _weatherMarkers;
            set => SetProperty(ref _weatherMarkers, value);

 < maps:SfMaps  x:Name="sfmap" EnablePanning="False" EnableZooming="False" BackgroundColor="Transparent" >
                < maps:SfMaps.Layers >
                    < maps:ShapeFileLayer x:Name="ShapeLayer" Uri="FRA_adm0.shp" MarkerTemplate="{Binding MarkerDataTemplate}" Markers="{Binding WeatherMarkers}" >
                        < maps:ShapeFileLayer.ShapeSettings >
                            < maps:ShapeSetting  ShapeFill="{StaticResource PrimaryColorOne}" ShapeStroke="white" ShapeStrokeThickness="2" >
                            < /maps:ShapeSetting >
                        < /maps:ShapeFileLayer.ShapeSettings >
                    < /maps:ShapeFileLayer >
                < /maps:SfMaps.Layers >
            < /maps:SfMaps >


2 Replies

RD Rjuken Developments January 18, 2019 02:15 PM

Okay so I found out what's going on.

I have to type my ObservableCollection to MapMarker and not WeatherMarker.  

    private ObservableCollection< MapMarker > _weatherMarkers;
        public ObservableCollection< MapMarker > WeatherMarkers
            get => _weatherMarkers;
            set => SetProperty(ref _weatherMarkers, value);

Instead of : 

    private ObservableCollection< WeatherMarker > _weatherMarkers;
        public ObservableCollection< WeatherMarker > WeatherMarkers
            get => _weatherMarkers;
            set => SetProperty(ref _weatherMarkers, value);

It should work with WeatherMarker as it derives from MapMarker. Anyway, working now. 

PR Padmini Ramamurthy Syncfusion Team January 21, 2019 01:41 AM

Hi Rjuken Developments, 
Glad that you have resolved the issue and please get back to us anytime if you need any other assistance. 
Padmini R. 

Live Chat Icon For mobile
Up arrow icon