Windows Phone ToolKit Map Error "Items must be empty before using Items Source"

94 views Asked by At

I have a Windows XAML page which contents a map as below from the codebehind using my viewmodels constructor. I want to display multiple locations in Map with a pointer so I am using Windows Phone toolkit

 <Controls:Map x:Name="AllyMap" Grid.Row="1" Center="{Binding GeoLocation}" ZoomLevel="12">
            <toolkit:MapExtensions.Children>
                <toolkit:MapItemsControl ItemsSource="{Binding MapList}">
                    <toolkit:MapItemsControl.ItemTemplate>
                        <DataTemplate>
                            <toolkit:Pushpin GeoCoordinate="{Binding GeoCoordinate}" Content="{Binding Content}"/>
                        </DataTemplate>
                    </toolkit:MapItemsControl.ItemTemplate>
                </toolkit:MapItemsControl>
            </toolkit:MapExtensions.Children>
        </Controls:Map>

Now I am binding with MapList Itemsource as below.

atmLocationsMapView = new ATMLocationsMapViewModel();
            this.DataContext = atmLocationsMapView;
            ObservableCollection<DependencyObject> Mapchildren = MapExtensions.GetChildren(AllyMap);
            MapItemsControl AllyMapObject;
            AllyMapObject = null;
            AllyMapObject = Mapchildren.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl;
            AllyMapObject.ItemsSource = atmLocationsMapView.MapList;

It is working fine with a first iteration. I have a feature to filter among the maps. When I am filtering it I am getting "Items must be empty before using Items Source" in the last line of the above code.

Can anybody please help me with this.

0

There are 0 answers