private void add_Clicked(object sender, EventArgs e) { EditorPage editorPage = new EditorPage(); editorPage.Disappearing += (object editorPageSender, EventArgs editorPageargs) => { if (editorPage.text == null) { return; } string text = editorPage.text; addNote(text); }; Navigation.PushAsync(editorPage); }
private void addNote_Clicked(object sender, EventArgs e) { EditorPage editorPage = new EditorPage(); editorPage.Disappearing += (object editorPageSender, EventArgs editorPageargs) => { if (editorPage.text == null || editorPage.text == "") { return; } string text = editorPage.text; DateTime time = DateTime.Now; addNote(text, time); safeNotes(); }; Navigation.PushAsync(editorPage); }
protected void addNote(string text, DateTime timeChanged, char pos = ' ') { Label noteText = new Label() { Margin = new Thickness(0, 0, 0, 5), LineBreakMode = LineBreakMode.TailTruncation, Text = text }; Label noteTime = new Label() { Margin = new Thickness(0, 0, 0, 0), LineBreakMode = LineBreakMode.TailTruncation, Text = timeChanged.ToString() }; StackLayout newNote = new StackLayout() { Margin = new Thickness(0, 0, 0, 0), Children = { noteText, noteTime } }; Frame newNoteFrame = new Frame() { BackgroundColor = Color.Bisque, BorderColor = Xamarin.Forms.Color.DarkSeaGreen, Margin = new Thickness(0, 0, 0, 0), Padding = new Thickness(15, 15, 0, 15), Content = newNote }; var pan = new PanGestureRecognizer(); double totalX = 0; pan.PanUpdated += async(panSender, panArgs) => { switch (panArgs.StatusType) { case GestureStatus.Canceled: case GestureStatus.Started: newNoteFrame.TranslationX = 0; break; case GestureStatus.Completed: if (totalX > 0 && rightContainer.Children.Contains(newNoteFrame)) { if (await DisplayAlert("Confirm the deleting", "Are you sure?", "Yes!", "No")) { rightContainer.Children.Remove(newNoteFrame); checkCount(); safeNotes(); } totalX = 0; } else if (totalX < 0 && leftContainer.Children.Contains(newNoteFrame)) { if (await DisplayAlert("Confirm the deleting", "Are you sure?", "Yes!", "No")) { leftContainer.Children.Remove(newNoteFrame); checkCount(); safeNotes(); } totalX = 0; } newNoteFrame.TranslationX = 0; break; case GestureStatus.Running: if (panArgs.TotalX > 0 && rightContainer.Children.Contains(newNoteFrame)) { newNoteFrame.TranslationX = panArgs.TotalX; totalX = panArgs.TotalX; } else if (panArgs.TotalX < 0 && leftContainer.Children.Contains(newNoteFrame)) { newNoteFrame.TranslationX = panArgs.TotalX; totalX = panArgs.TotalX; } break; } }; newNote.GestureRecognizers.Add(pan); if (pos == 'l') { leftContainer.Children.Add(newNoteFrame); } else if (pos == 'r') { rightContainer.Children.Add(newNoteFrame); } else { if (leftContainer.Children.Count <= rightContainer.Children.Count) { leftContainer.Children.Add(newNoteFrame); } else { rightContainer.Children.Add(newNoteFrame); } } var tap = new TapGestureRecognizer(); tap.Tapped += (tapSender, tapEven) => { EditorPage editorPage_ = new EditorPage(timeChanged, text); Navigation.PushAsync(editorPage_); editorPage_.Disappearing += (_, __) => { text = editorPage_.text; noteText.Text = text; timeChanged = editorPage_.timeChanged; noteTime.Text = timeChanged.ToString(); }; }; newNote.GestureRecognizers.Add(tap); }
protected void addNote(string text, DateTime timeChanged, char pos = ' ') { Label noteText = new Label() { Margin = new Thickness(0, 0, 5, 5), LineBreakMode = LineBreakMode.TailTruncation, TextColor = Color.Black, Text = text }; Label noteTime = new Label() { LineBreakMode = LineBreakMode.TailTruncation, Text = timeChanged.ToString() }; StackLayout newNote = new StackLayout() { Children = { noteText, noteTime } }; Frame newNoteFrame = new Frame() { BackgroundColor = Color.AliceBlue, BorderColor = Xamarin.Forms.Color.YellowGreen, Padding = new Thickness(15, 15, 0, 15), Content = newNote }; //--сдвиги-- var pan = new PanGestureRecognizer(); double totalX = 0; //распознователь pan.PanUpdated += async(panSender, panArgs) => { switch (panArgs.StatusType) { case GestureStatus.Canceled: case GestureStatus.Started: //степень перемещенеия элемента newNoteFrame.TranslationX = 0; break; case GestureStatus.Completed: if (totalX > 0 && rightContainer.Children.Contains(newNoteFrame)) { if (await DisplayAlert("Подтверждение удаления", "Удалить заметку безвозвратно?", "Да", "Нет")) { rightContainer.Children.Remove(newNoteFrame); checkCount(); safeNotes(); } totalX = 0; } else if (totalX < 0 && leftContainer.Children.Contains(newNoteFrame)) { if (await DisplayAlert("Подтверждение удаления", "Удалить заметку безвозвратно?", "Да", "Нет")) { leftContainer.Children.Remove(newNoteFrame); checkCount(); safeNotes(); } totalX = 0; } newNoteFrame.TranslationX = 0; break; case GestureStatus.Running: if (panArgs.TotalX > 0 && rightContainer.Children.Contains(newNoteFrame)) { newNoteFrame.TranslationX = panArgs.TotalX; totalX = panArgs.TotalX; } else if (panArgs.TotalX < 0 && leftContainer.Children.Contains(newNoteFrame)) { newNoteFrame.TranslationX = panArgs.TotalX; totalX = panArgs.TotalX; } break; } }; //выбираем стек newNote.GestureRecognizers.Add(pan); if (pos == 'l') { leftContainer.Children.Add(newNoteFrame); } else if (pos == 'r') { rightContainer.Children.Add(newNoteFrame); } else { if (leftContainer.Children.Count <= rightContainer.Children.Count) { leftContainer.Children.Add(newNoteFrame); } else { rightContainer.Children.Add(newNoteFrame); } } var tapOpen = new TapGestureRecognizer(); tapOpen.Tapped += (tapSender, tapEven) => { //залетаем в редактирование (перегруженную функцию) EditorPage edit = new EditorPage(timeChanged, text); Navigation.PushAsync(edit); edit.Disappearing += (_, __) => { text = edit.text; noteText.Text = text; timeChanged = edit.timeChanged; noteTime.Text = timeChanged.ToString(); checkCount(); safeNotes(); }; }; newNote.GestureRecognizers.Add(tapOpen); }