コード例 #1
0
 private void DeleteFavorite(IFavorite favorite)
 {
     if (ListSelectionMode == ListViewSelectionMode.Multiple &&
         _selectedItems != null &&
         _selectedItems.Count > 0)
     {
         _favoritesService.RemoveFavorite(_selectedItems.Cast <IFavorite>());
     }
     else
     {
         _favoritesService.RemoveFavorite(favorite);
     }
 }
コード例 #2
0
        private async void AddToFavoriteButton_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            e.Handled = true;

            FavoritePlace existingFavorite = (await _favoritesService.GetFavoritesAsync()).FirstOrDefault(x => x == SelectedPlace) as FavoritePlace;

            if (existingFavorite != null)
            {
                _favoritesService.RemoveFavorite(existingFavorite);
                SelectedPlace = new Place
                {
                    Confidence = SelectedPlace.Confidence,
                    Lat        = SelectedPlace.Lat,
                    Lon        = SelectedPlace.Lon,
                    Id         = SelectedPlace.Id,
                    Name       = SelectedPlace.Name,
                    StringId   = SelectedPlace.StringId,
                    Type       = PlaceType.Address
                };
                return;
            }

            var newFavoritePlace = new FavoritePlace
            {
                FontIconGlyph  = FontIconGlyphs.FilledStar,
                Id             = Guid.NewGuid(),
                IconFontFace   = ((FontFamily)App.Current.Resources[Constants.SymbolThemeFontResource]).Source,
                IconFontSize   = Constants.SymbolFontSize,
                Lat            = SelectedPlace.Lat,
                Lon            = SelectedPlace.Lon,
                Name           = SelectedPlace.Name,
                Type           = PlaceType.FavoritePlace,
                UserChosenName = SelectedPlace.Name
            };

            _favoritesService.AddFavorite(newFavoritePlace);
            SelectedPlace = newFavoritePlace;
        }