public NewNotePage(NoteVM vm) { NavigationPage.SetHasBackButton(this, false); Title = "Новая заметка"; ViewModel = vm; BindingContext = ViewModel; count_subtasks = 0; nameEntry = new CustomEditor2 { Placeholder = "Введите название", TextColor = Color.FromHex("0D47A1"), //PlaceholderColor = Color.DarkGray, FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Entry)), Margin = new Thickness(0, 10, 0, 0), }; nameEntry.SetBinding(Editor.TextProperty, "Name"); nameEntry.TextChanged += NameEntry_TextChanged; //////комментарий commentEditor = new CustomEditor2 { TextColor = Color.FromHex("0D47A1"), Placeholder = "Добавьте комментарий", }; commentEditor.TextChanged += Editor_TextChanged; commentEditor.SetBinding(CustomEditor2.TextProperty, "Comment"); Grid commentGrid = new Grid { ColumnDefinitions = { new ColumnDefinition { Width = GridLength.Auto }, new ColumnDefinition { Width = GridLength.Auto }, }, Margin = new Thickness(0, 20, 0, 0) }; commentGrid.Children.Add(new Label { Text = "//", WidthRequest = 20, FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)), VerticalTextAlignment = TextAlignment.Start, HorizontalTextAlignment = TextAlignment.Center }, 0, 0); commentGrid.Children.Add(commentEditor, 1, 0); /////////////////////подзадачи Label subtaskLabel = new Label { Text = "Добавить подзадачу", VerticalOptions = LayoutOptions.Center, Margin = new Thickness(2, 0, 0, 0) }; StackLayout subdefaultSL = new StackLayout { Children = { new Label { Text = "➥", FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), HorizontalOptions = LayoutOptions.Center, Margin = new Thickness(3, 0, 0, 0) }, subtaskLabel }, Orientation = StackOrientation.Horizontal }; subtasksSL = new StackLayout { Children = { subdefaultSL }, Margin = new Thickness(25, 11, 0, 0) }; subtaskLabel.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(() => { count_subtasks++; CustomButton donesubtaskButton = new CustomButton { FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Button)), WidthRequest = 23, HeightRequest = 23, BorderRadius = 12, BackgroundColor = Color.White, BorderWidth = 1, BorderColor = Color.Gray, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Start, Margin = new Thickness(0, 3, 0, 0) }; CustomEditor2 newsubtaskEditor = new CustomEditor2 { Placeholder = "Введите название", TextColor = Color.FromHex("0D47A1"), FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Entry)), HorizontalOptions = LayoutOptions.FillAndExpand, WidthRequest = 240 }; Label removesubtaskLabel = new Label { Text = "✖", HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, BackgroundColor = Color.Transparent, Margin = new Thickness(-6, 2, 0, 0), TextColor = Color.Gray, WidthRequest = 35, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Start, }; StackLayout newsubtaskSL = new StackLayout { Children = { donesubtaskButton, newsubtaskEditor, removesubtaskLabel }, Orientation = StackOrientation.Horizontal }; newsubtaskEditor.TextChanged += (sender, e) => { var element = sender as CustomEditor2; if (String.IsNullOrWhiteSpace(element.Text) == false) { element.Text = element.Text.Substring(0, 1).ToUpper() + element.Text.Remove(0, 1); } else { donesubtaskButton.Text = ""; element.Text = element.Text.TrimStart(); } }; if (subtasksSL.Children[0] == subdefaultSL) { subtasksSL.Children.Remove(subdefaultSL); } if (subtasksSL.Children.Count > 1) { subtasksSL.Children.Remove(subdefaultSL); } subtasksSL.Children.Add(newsubtaskSL); subtasksSL.Children.Add(subdefaultSL); donesubtaskButton.Clicked += (sender, e) => { if (String.IsNullOrWhiteSpace(newsubtaskEditor.Text) == false) { if (Addition.IsStrikethrough(newsubtaskEditor.Text) == true) { donesubtaskButton.Text = ""; newsubtaskEditor.Text = Addition.ConvertFromStrikethrough(newsubtaskEditor.Text); } else { donesubtaskButton.Text = "✔"; newsubtaskEditor.Text = Addition.ConvertToStrikethrough(newsubtaskEditor.Text); } } }; removesubtaskLabel.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(() => { count_subtasks--; subtasksSL.Children.Remove(newsubtaskSL); }) }); }) }); ////////////дата Image dateImage = new Image { Source = "calendar.png", WidthRequest = 17.5, HeightRequest = 17.5, Margin = new Thickness(2, 0, 0, 0) }; //datePicker = new CustomDatePicker //{ // Format = "Сегодня", // FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(CustomDatePicker)), // MinimumDate = DateTime.Today, // WidthRequest = 165, // HeightRequest = 35, // HorizontalOptions=LayoutOptions.Start, // Margin = new Thickness(1, 0, 0, 0) //}; //datePicker.DateSelected += DatePicker_DateSelected; //datePicker.SetBinding(CustomDatePicker.DateProperty, "Date"); datePicker = new CustomDatePicker { Format = "Сегодня", FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(CustomDatePicker)), MinimumDate = DateTime.Today, WidthRequest = 165, HeightRequest = 35, HorizontalOptions = LayoutOptions.Start, Margin = new Thickness(1, 0, 0, 0) }; datePicker.DateSelected += DatePicker_DateSelected; datePicker.SetBinding(CustomDatePicker.DateProperty, "Date"); StackLayout dateStackLayout = new StackLayout { Orientation = StackOrientation.Horizontal, Margin = new Thickness(0, 11, 0, 0), Children = { dateImage, datePicker } }; /////////////// //Label markerlabel = new Label //{ // Margin = new Thickness(0, 11, 0, 0), // Text = "Пометить?", // FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), //}; Button colorButton0 = new Button { Style = Addition.buttonStyle2, BackgroundColor = Color.FromHex("ffffff"), Text = "✔" }; colorButton0.Clicked += ColorButton_Clicked; lastButton_int = colorButton0.GetHashCode(); Button colorButton1 = new Button { Style = Addition.buttonStyle2, BackgroundColor = Color.FromHex("ff897d") }; colorButton1.Clicked += ColorButton_Clicked; Button colorButton2 = new Button { Style = Addition.buttonStyle2, BackgroundColor = Color.FromHex("ffd27a") }; colorButton2.Clicked += ColorButton_Clicked; Button colorButton3 = new Button { Style = Addition.buttonStyle2, BackgroundColor = Color.FromHex("cbff8a") }; colorButton3.Clicked += ColorButton_Clicked; Button colorButton4 = new Button { Style = Addition.buttonStyle2, BackgroundColor = Color.FromHex("80afff") }; colorButton4.Clicked += ColorButton_Clicked; Button colorButton5 = new Button { Style = Addition.buttonStyle2, BackgroundColor = Color.FromHex("b484ff") }; colorButton5.Clicked += ColorButton_Clicked; Button colorButton6 = new Button { Style = Addition.buttonStyle2, BackgroundColor = Color.FromHex("f9bad0") }; colorButton6.Clicked += ColorButton_Clicked; Button colorButton7 = new Button { Style = Addition.buttonStyle2, BackgroundColor = Color.FromHex("cfd8dc") }; colorButton7.Clicked += ColorButton_Clicked; chooseColorSL = new StackLayout { Children = { colorButton0, colorButton1, colorButton2, colorButton3, colorButton4, colorButton5, colorButton6, colorButton7 }, Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.Center, Margin = new Thickness(0, 20, 0, 0), }; /////////////////////////////////////////// Label repeatlabel = new Label { Text = "Каждый день", //Margin = new Thickness(0, 3, 0, 0), FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), //HorizontalOptions = LayoutOptions.End }; repeatSwitch = new Switch(); /*{ HorizontalOptions=LayoutOptions.EndAndExpand};*/ repeatSwitch.SetBinding(Switch.IsToggledProperty, "Repeat"); //repeatSwitch.Toggled += RepeatSwitch_Toggled; StackLayout repeatSL = new StackLayout { Orientation = StackOrientation.Horizontal, Margin = new Thickness(0, 11, 0, 0), Children = { repeatlabel, repeatSwitch } }; mondayButton = new Button { Text = "П", Style = Addition.buttonStyle }; mondayButton.Clicked += Button_Clicked; tuesdayButton = new Button { Text = "В", Style = Addition.buttonStyle }; tuesdayButton.Clicked += Button_Clicked; wednesdayButton = new Button { Text = "С", Style = Addition.buttonStyle }; wednesdayButton.Clicked += Button_Clicked; thursdayButton = new Button { Text = "Ч", Style = Addition.buttonStyle }; thursdayButton.Clicked += Button_Clicked; fridayButton = new Button { Text = "П", Style = Addition.buttonStyle }; fridayButton.Clicked += Button_Clicked; saturdayButton = new Button { Text = "С", Style = Addition.buttonStyle }; saturdayButton.Clicked += Button_Clicked; sundayButton = new Button { Text = "В", Style = Addition.buttonStyle }; sundayButton.Clicked += Button_Clicked; choosedaysSL = new StackLayout { Children = { mondayButton, tuesdayButton, wednesdayButton, thursdayButton, fridayButton, saturdayButton, sundayButton }, Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.Center, Margin = new Thickness(0, 5, 0, 0), }; choosedaysSL.SetBinding(IsVisibleProperty, "Repeat"); ///////////////////////////////// addButton = new Button { Text = "✔", BackgroundColor = Color.White, TextColor = Color.Gray, IsEnabled = false }; addButton.Pressed += AddButton_Clicked; //addButton.Clicked += AddButton_Clicked; Button backButton = new Button { Text = "➥", BackgroundColor = Color.White, TextColor = Color.FromHex("0D47A1") }; backButton.SetBinding(Button.CommandProperty, "ListViewModel.BackCommand"); //backButton.Clicked += RemoveSelectedItem; StackLayout buttonsStackLayout = new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.EndAndExpand, Children = { addButton, backButton } }; //Label0 = new Label { Text = "switch:" + ViewModel.Repeat }; //Label1 = new Label { Text = "Пон:" + ViewModel.everyMonday }; //Label2 = new Label { Text = "Вт:" + ViewModel.everyTuesday }; //Label3 = new Label { Text = "Ср:" + ViewModel.everyWednesday }; //Label4 = new Label { Text = "Чет:" + ViewModel.everyThursday }; //Label5 = new Label { Text = "Пят:" + ViewModel.everyFriday }; //Label6 = new Label { Text = "Суб:" + ViewModel.everySaturday }; //Label7 = new Label { Text = "Воскр:" + ViewModel.everySunday }; Label0 = new Label(); Label1 = new Label(); Button button = new Button { Text = "check" }; button.Clicked += (sender, e) => { string str = null; int count = 0; for (int i = 0; i <= count_subtasks - 1; i++) { if (String.IsNullOrEmpty(((subtasksSL.Children[i] as StackLayout).Children[1] as CustomEditor2).Text) == false) { str += ((subtasksSL.Children[i] as StackLayout).Children[1] as CustomEditor2).Text + "✖"; count++; } } Label0.Text = str; Label1.Text = count.ToString(); }; ScrollView scrollView = new ScrollView { Content = new StackLayout { Children = { nameEntry, commentGrid, subtasksSL, dateStackLayout, repeatSL, /*choosedaysSL,*/ /*markerlabel,*/ chooseColorSL, //Label0, //Label1, //button, //Label2,Label3,Label4,Label5,Label6,Label7, buttonsStackLayout }, BackgroundColor = Color.White, Padding = new Thickness(15) } }; Content = scrollView; }
public static void EditNote(NoteVM vm) { count_subtasks = 0; str = null; str_old = null; subtasksSL.Children.Clear(); //subtasksSL.Children.Add(subdefaultSL); editnote = vm; nameEntry.Text = vm.Name; commentEntry.Text = vm.Comment; str_old = vm.Subtasks_string; if (String.IsNullOrEmpty(str_old) == false) { string[] subtasks_array = str_old.Split(new char[] { '✖' }); foreach (char s in str_old) { if (s == '✖') { count_subtasks++; } } for (int i = 1; i <= count_subtasks; i++) { CustomButton donesubtaskButton = new CustomButton { FontSize = 15, WidthRequest = 23, FontFamily = "Segoe MDL2 Assets", HeightRequest = 23, BorderRadius = 12, BackgroundColor = Color.White, BorderWidth = 1, BorderColor = Color.Gray, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Start, Margin = new Thickness(0, 5, 0, 0) }; CustomEditor2 newsubtaskEditor = new CustomEditor2 { Placeholder = "Введите название", FontFamily = "Open Sans", TextColor = Color.FromHex("0D47A1"), AutoSize = EditorAutoSizeOption.TextChanges, WidthRequest = 282, BackgroundColor = Color.Transparent, Text = subtasks_array[i - 1], }; //if (Addition.IsStrikethrough(newsubtaskEditor.Text) == true) // donesubtaskButton.Text = "\uE73E"; if (subtasks_array[i - 1].StartsWith("➥") == true) { donesubtaskButton.Text = "\uE73E"; newsubtaskEditor.Text = newsubtaskEditor.Text.Remove(0, 1); } Label removesubtaskLabel = new Label { FontFamily = "Segoe MDL2 Assets", Text = "\uE894", HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, BackgroundColor = Color.Transparent, Margin = new Thickness(-6, 7, 0, 0), TextColor = Color.Gray, WidthRequest = 35, HorizontalOptions = LayoutOptions.EndAndExpand, VerticalOptions = LayoutOptions.Start, }; StackLayout newsubtaskSL = new StackLayout { Children = { donesubtaskButton, newsubtaskEditor, removesubtaskLabel }, Orientation = StackOrientation.Horizontal, Margin = 0 }; newsubtaskEditor.TextChanged += (sender2, e2) => { if (String.IsNullOrWhiteSpace(newsubtaskEditor.Text) == false) { newsubtaskEditor.Text = newsubtaskEditor.Text.Substring(0, 1).ToUpper() + newsubtaskEditor.Text.Remove(0, 1); } else { donesubtaskButton.Text = ""; newsubtaskEditor.Text = newsubtaskEditor.Text.TrimStart(); } }; if (subtasksSL.Children.Count > 1) { subtasksSL.Children.Remove(subdefaultSL); } subtasksSL.Children.Add(newsubtaskSL); subtasksSL.Children.Add(subdefaultSL); string str2 = subtasks_array[i - 1]; donesubtaskButton.Clicked += (sender3, e3) => { if (String.IsNullOrWhiteSpace(newsubtaskEditor.Text) == false) { if (str2.StartsWith("➥") == true) { donesubtaskButton.Text = ""; //newsubtaskEditor.Text = newsubtaskEditor.Text.Remove(0, 1); subtasks_array[i - 1] = str2.Remove(0, 1); } else { donesubtaskButton.Text = "\uE73E"; //newsubtaskEditor.Text = "➥"+ newsubtaskEditor.Text; subtasks_array[i - 1] = "➥" + str2; } //if (Addition.IsStrikethrough(newsubtaskEditor.Text) == true) //{ // donesubtaskButton.Text = ""; // newsubtaskEditor.Text = Addition.ConvertFromStrikethrough(newsubtaskEditor.Text); //} //else //{ // donesubtaskButton.Text = "\uE73E"; // newsubtaskEditor.Text = Addition.ConvertToStrikethrough(newsubtaskEditor.Text); //} } }; removesubtaskLabel.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(() => { count_subtasks--; subtasksSL.Children.Remove(newsubtaskSL); }) }); } } else { subtasksSL.Children.Add(subdefaultSL); } //(StackLayout.Children[0] as Label).Text = vm.Subtasks_string; //(newnoteSL.Children[0] as Label).Text = "сount: "+count_subtasks.ToString() +"\n"+ // "str: "+str+"\n"+ // "str_old: "+str_old; if (editnote.Date >= DateTime.Today) { datePicker.MinimumDate = DateTime.Today; } else { datePicker.MinimumDate = vm.Date; } datePicker.Date = vm.Date; foreach (Button btn in chooseColorSL.Children) { btn.Text = ""; lastButton_int = 0; } foreach (Button btn in chooseColorSL.Children) { if (Addition.HexConverter(btn.BackgroundColor) == vm.ColorMarker_string) { btn.Text = "\uE73E"; lastButton_int = btn.GetHashCode(); additionButton.BackgroundColor = btn.BackgroundColor; } } repeatSwitch.IsToggled = vm.Repeat; newnoteSL.IsVisible = true; edit = true; removeButton.IsVisible = true; addnewnoteButton.Text = "Сохранить"; MainPage_UWP.addImage.Source = "images/cross.png"; }