private async void AddButton_Clicked(object sender, EventArgs e) { bool isEntryRight = true; if (NameEntry.Text == null) { await DisplayAlert(Resource.Error, Resource.EnterTheNameOfConstellation, Resource.OK); isEntryRight = false; } if (isEntryRight) { string uri = ImageEntry.Text ?? ""; Collection <Star> stars = new Collection <Star>(); for (int i = 0, count = NamesOfStars.Count; i < count - 1; i++) { if (NamesOfStars.ElementAt(i).Value != -1) { stars.Add(Stars.ElementAt(i)); } } if (Constellation != null) { bool result = await DisplayAlert(Resource.ConfirmAction, Resource.AreYouSureYouWantToReplaceTheData, Resource.Yes, Resource.No); if (!result) { return; } await DisplayAlert(Resource.Notification, Resource.TheDataWasSuccessfullyReplaced, Resource.OK); Constellation.Name = NameEntry.Text; Constellation.ImageOfConstellation = uri; Constellation.Stars.Clear(); foreach (var s in stars) { Constellation.Stars.Add(s); } Constellation.DefinePosition(); } else { Data.Constellations.Add(new Constellation(NameEntry.Text, uri, stars)); await DisplayAlert(Resource.Notification, Resource.DataWasSuccessfullyAdded, Resource.OK); } await Navigation.PopModalAsync(); } }
public InformationAboutTheConstellationPage(Constellation constellation) { InitializeComponent(); this.BindingContext = constellation; Constellation = constellation; try { ImageOfConstellation.Source = new UriImageSource { Uri = new Uri(constellation.ImageOfConstellation) }; } catch (Exception) { ImageOfConstellation.Source = null; ImageOfConstellation.HeightRequest = 0; } }
public AddingNewConstellationPage(Constellation constellation) { InitializeComponent(); Constellation = constellation; Stars = new Collection <Star>(); NamesOfStars = new Dictionary <string, int>(); for (int i = 0, count = Data.Stars.Count; i < count; i++) { if (Data.Stars[i].Constellation == null) { Stars.Add(Data.Stars[i]); } } for (int i = 0, count = Constellation.Stars.Count; i < count; i++) { Stars.Add(Constellation.Stars[i]); } for (int i = 0, count = Stars.Count; i < count; i++) { NamesOfStars.Add(Stars[i].Name, -1); } NameEntry.Text = Constellation.Name; ImageEntry.Text = Constellation.ImageOfConstellation; StarPicker picker = new StarPicker(NamesOfStars); StackLayout stack = new StackLayout() { Orientation = StackOrientation.Horizontal }; stack.Children.Add(picker); StarsStack.Children.Add(stack); picker.SelectedIndexChanged += StarPicker_SelectedIndexChanged; for (int i = 0, count = Constellation.Stars.Count; i < count; i++) { picker = (StarPicker)((StackLayout)StarsStack.Children[i]).Children[0]; picker.SelectedItem = Constellation.Stars[i].Name; } AddButton.Text = Resource.Save; }