private void ShowEditBox() { TextBoxName.Visibility = Windows.UI.Xaml.Visibility.Visible; PageTitle.Visibility = Windows.UI.Xaml.Visibility.Collapsed; TextBoxName.Focus(Windows.UI.Xaml.FocusState.Programmatic); TextBoxName.SelectAll(); }
public void ButtonEdit_Click(object sender, EventArgs e) { if (ButtonEdit.Content.Equals("Edit")) // .Equals is required instead of == { ButtonEdit.Background = brush2; ButtonEdit.Content = "Save"; // enable text boxes to be edited TextBoxName.IsReadOnly = false; TextBoxAge.IsReadOnly = false; // change the colour of the textboxes while they are being edited TextBoxAge.Background = (SolidColorBrush)Brushes.White; TextBoxName.Background = (SolidColorBrush)Brushes.White; // to keep the add button disabled ButtonAdd.IsEnabled = false; // to highlight the text of the rabbit name TextBoxName.Focus(); TextBoxName.SelectAll(); } else { ButtonEdit.Background = brush3; ButtonEdit.Content = "Edit"; if ((TextBoxAge.Text.Length > 0) && (TextBoxName.Text.Length > 0)) { // must have selected a rabbit if (rabbit != null) { rabbit.Name = TextBoxName.Text; if (int.TryParse(TextBoxAge.Text, out int age)) { rabbit.AGE = age; } using (var db = new RabbitDbEntities()) { // read rabbit from database by ID var rabbitToUpdate = db.Rabbits.Find(rabbit.RabbitId); // read rabbit rabbitToUpdate.Name = rabbit.Name; rabbitToUpdate.AGE = rabbit.AGE; // save rabbit back to db db.SaveChanges(); // clear listbox because we're going to change (the binding) rabbit = null; // remove the binding rabbit // ListBoxRabbit.ItemsSource = null; // remove binding //ListBoxRabbit.Items.Clear(); // clear it out // repopulate listbox // re-read from db rabbits = db.Rabbits.ToList(); // get rabbits ListBoxRabbit.ItemsSource = rabbits; // bind to listbox again } } //TextBoxAge.Text = ""; //TextBoxName.Text = ""; TextBoxAge.IsReadOnly = true; TextBoxName.IsReadOnly = true; } } }
private void ButtonEdit_Click(object sender, RoutedEventArgs e) { if (ButtonEdit.Content.Equals("Edit")) { Color color = (Color)ColorConverter.ConvertFromString("#007ED9"); var brush = new SolidColorBrush(color); ButtonEdit.Background = brush; ButtonEdit.Content = "Save"; TextBoxName.IsReadOnly = false; TextBoxAge.IsReadOnly = false; ButtonAdd.IsEnabled = false; TextBoxName.Focus(); TextBoxName.SelectAll(); } else { ButtonEdit.Content = "Edit"; if ((TextBoxAge.Text.Length > 0) && (TextBoxName.Text.Length > 0)) { if (rabbit != null) { rabbit.Name = TextBoxName.Text; if (int.TryParse(TextBoxAge.Text, out int age)) { rabbit.Age = age; } using (var db = new RabbitDbEntities()) { //read rabbit from database by the ID var rabbitToUpdate = db.Rabbits.Find(rabbit.RabbitId); //update the rabbit and save it back to DB rabbitToUpdate.Name = rabbit.Name; rabbitToUpdate.Age = rabbit.Age; //save it back to db db.SaveChanges(); //Clear list box because we will change it rabbit = null; ListBoxRabbit.ItemsSource = null; //remove binding ListBoxRabbit.Items.Clear(); //clears it //repopulate list box rabbits = db.Rabbits.ToList(); ListBoxRabbit.ItemsSource = rabbits; } } } ButtonAdd.IsEnabled = false; } }
private void ButtonEdit_Click(object sender, RoutedEventArgs e) { if (ButtonEdit.Content.Equals("Edit")) { // Color color = (Color)ColorConverter.ConvertFromString("#FF1D3A"); ButtonEdit.Content = "Save"; ButtonEdit.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FF1D3A")); TextBoxAge.IsReadOnly = false; TextBoxName.IsReadOnly = false; ButtonAdd.IsEnabled = false; TextBoxName.Focus(); TextBoxName.SelectAll(); } else //Save mode { ButtonEdit.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#E8C3E3")); ButtonEdit.Content = "Edit"; TextBoxAge.IsReadOnly = true; TextBoxName.IsReadOnly = true; if (TextBoxAge.Text.Length > 0 && TextBoxName.Text.Length > 0) { //must have a rabbit selected if (rabbit != null) { rabbit.Name = TextBoxName.Text; if (int.TryParse(TextBoxAge.Text, out int age)) { rabbit.Age = age; } //Read Rabbit from database by the ID using (var db = new RabbitDbEntities()) { //Read Rabbit from database by the ID var rabbitToUpdate = db.Rabbits.Find(rabbit.RabbitId); //UPDATE rabbit, save it back to the database rabbitToUpdate.Name = rabbit.Name; rabbitToUpdate.Age = rabbit.Age; db.SaveChanges(); //CLEAR listbox - Remove binding, Clear it out //rabbit = null; //listBoxRabbits.ItemsSource = null; //listBoxRabbits.Items.Clear(); //REPOPULATE - get rabbits, bind rabbits = db.Rabbits.ToList(); listBoxRabbits.ItemsSource = rabbits; } } ButtonAdd.IsEnabled = true; } } }
public NameStateDialog() { InitializeComponent(); Application curApp = Application.Current; Window mainWindow = curApp.MainWindow; this.Left = mainWindow.Left + (mainWindow.Width - this.ActualWidth - 400) / 2; this.Top = mainWindow.Top + (mainWindow.Height - this.ActualHeight - 600) / 2; this.Topmost = true; TextBoxName.SelectAll(); }
public FormSavePlaylist(ISaveSupport aSaveSupport) { InitializeComponent(); iSaveSupport = aSaveSupport; Size = new System.Drawing.Size(470, 123); TextBoxName.Text = aSaveSupport.DefaultName; TextBoxName.SelectAll(); TextBoxName.Focus(); }
private void ButtonEdit_Click(object sender, RoutedEventArgs e) { if (ButtonEdit.Content.Equals("Edit")) { ButtonEdit.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#9589FF")); ButtonEdit.Content = "Save"; TextBoxName.IsReadOnly = false; TextBoxAge.IsReadOnly = false; TextBoxName.Background = (SolidColorBrush)Brushes.White; TextBoxAge.Background = (SolidColorBrush)Brushes.White; ButtonAdd.IsEnabled = false; TextBoxName.Focus(); TextBoxName.SelectAll(); } else { Color color = (Color)ColorConverter.ConvertFromString("#B3C6ED"); var brush = new SolidColorBrush(color); ButtonEdit.Background = brush; ButtonEdit.Content = "Edit"; if ((TextBoxAge.Text.Length > 0) && (TextBoxName.Text.Length > 0)) { // must have selected a rabbit if (rabbit != null) { rabbit.Name = TextBoxName.Text; if (int.TryParse(TextBoxAge.Text, out int age)) { rabbit.Age = age; } using (var db = new RabbitDbEntities()) { // read rabbit from database by ID var rabbitToUpdate = db.Rabbits.Find(rabbit.RabbitId); // update rabbit rabbitToUpdate.Name = rabbit.Name; rabbitToUpdate.Age = rabbit.Age; // save rabbit back to DB db.SaveChanges(); // clear listbox because we're going to change (the binding) rabbit = null; // remove binding on rabbit // ListBoxRabbits.ItemsSource = null; // remove binding // ListBoxRabbits.Items.Clear(); // clear it out // repopulate listbox // re-read from db rabbits = db.Rabbits.ToList(); // get rabbits ListBoxRabbits.ItemsSource = rabbits; // bind to listbox again } } } ButtonAdd.IsEnabled = true; } }
private void EnterEditSaveMode() { ButtonEdit.Content = "Save"; ButtonEdit.Background = ButtonsSecondMode; ButtonAdd.Background = ButtonsFirstMode; ButtonDelete.Background = ButtonsFirstMode; TextBoxName.Background = EditableBrush; TextBoxAge.Background = EditableBrush; TextBoxName.IsReadOnly = false; TextBoxAge.IsReadOnly = false; ButtonAdd.IsEnabled = false; ButtonEdit.IsEnabled = true; ButtonDelete.IsEnabled = true; TextBoxName.Focus(); TextBoxName.SelectAll(); }