// synchronize changes in the view model collection with the map push pins void Results_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { // the synchronization requires a reference to a Bing.Maps object on the Main page if (Map == null) { throw new System.NullReferenceException("An instance of Bing.Maps is required here, yet the Map property was found to be null."); } // only additions and wholesale reset of the ObservableCollection are currently supported switch (e.Action) { case NotifyCollectionChangedAction.Add: foreach (var item in e.NewItems) { IMappable mapItem = (IMappable)item; PointOfInterestPin poiPin = new PointOfInterestPin(mapItem); poiPin.Selected += (s, e2) => { MappableListView.SelectedItem = MappableListView.Items.Where((c) => (c as IMappable).Id == e2.PointOfInterest.Id).FirstOrDefault(); }; Map.AddPointOfInterestPin(poiPin, mapItem.Position); } break; case NotifyCollectionChangedAction.Reset: Map.ClearPointOfInterestPins(); break; // case NotifyCollectionChangedAction.Remove: // // TODO: (optional) if your application allows items to be selectively removed from the view model // code to remove a single associated push pin will be required. // // // // break; // not implemented in this context // case NotifyCollectionChangedAction.Replace: // case NotifyCollectionChangedAction.Move: } }
/// <summary> /// Synchronizes changes to the ApiViewModel's Results collection. The elements of that collection are assumed /// to implement IMappable (see the APIMASH_TomTom.TomTomCameraViewModel implementation for a sample reference). /// This code should require no changed regardless as long as the items in the Results collection implement IMappable. /// </summary> void Results_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { // only additions and wholesale reset of the ObservableCollection are currently supported switch (e.Action) { case NotifyCollectionChangedAction.Add: foreach (var item in e.NewItems) { IMappable mapItem = (IMappable)item; PointOfInterestPin poiPin = new PointOfInterestPin(mapItem); poiPin.Tap += async(s, e2) => { TheMap.HighlightPointOfInterestPin(DefaultViewModel.SelectedItem, false); TheMap.HighlightPointOfInterestPin(poiPin.PointOfInterest, true); await ProcessSelectedItem(item); }; TheMap.AddPointOfInterestPin(poiPin, mapItem.Position); } break; case NotifyCollectionChangedAction.Reset: TheMap.ClearPointOfInterestPins(); break; // case NotifyCollectionChangedAction.Remove: // // TODO: (optional) if your application allows items to be selectively removed from the view model // code to remove a single associated push pin will be required. // // // // break; // not implemented in this context // case NotifyCollectionChangedAction.Replace: // case NotifyCollectionChangedAction.Move: } }