Пример #1
0
 public MainViewModel()
 {
     Restaurants.CollectionChanged += async(s, e) =>
     {
         if (e.NewItems != null)
         {
             foreach (Restaurant restaurant in e.NewItems)
             {
                 MappedLocations.Add(
                     new MappedLocation
                 {
                     Restaurant = restaurant,
                     Index      = Restaurants.IndexOf(restaurant) + 1,
                     Position   = new BasicGeoposition
                     {
                         Latitude  = restaurant.Latitude,
                         Longitude = restaurant.Longitude
                     }
                 });
                 if (restaurant.Distance == 0)
                 {
                     await SetDistanceAsync(restaurant);
                 }
             }
         }
         if (e.OldItems != null)
         {
             foreach (Restaurant restaurant in e.OldItems)
             {
                 MappedLocations.Remove(MappedLocations.First(location => location.Restaurant == restaurant));
             }
             foreach (var location in MappedLocations)
             {
                 location.Index = Restaurants.IndexOf(location.Restaurant) + 1;
             }
         }
     };
 }