private void AddAccount_Click(object sender, RoutedEventArgs e) { SetAccount acc_new = new SetAccount(); Button deleteButton = new Button(); deleteButton.Content = "X"; deleteButton.SetValue(NameProperty, "delBut"); deleteButton.Margin = new Thickness(10, 0, 0, 0); deleteButton.Width = 20; deleteButton.Click += deleteButton_Click; deleteButton.Background = new SolidColorBrush(Color.FromRgb(156, 42, 42)); deleteButton.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); acc_new.accRow.Children.Add(deleteButton); AccountsList.Children.Add(acc_new); }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { DataTable tableLoad = new DataTable() { TableName = "accounts" }; tableLoad.Columns.Add("Owner"); tableLoad.Columns.Add("Path"); StringReader reader = new StringReader(Properties.Settings.Default.TableXml); tableLoad.ReadXml(reader); for (int i = 0; i < tableLoad.Rows.Count; i++) { SetAccount acc_new = new SetAccount(); Button deleteButton = new Button(); deleteButton.Content = "X"; deleteButton.SetValue(NameProperty, "delBut"); deleteButton.Margin = new Thickness(10, 0, 0, 0); deleteButton.Width = 20; deleteButton.Click += deleteButton_Click; deleteButton.Background = new SolidColorBrush(Color.FromRgb(156, 42, 42)); deleteButton.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); acc_new.accRow.Children.Add(deleteButton); AccountsList.Children.Add(acc_new); } int xL = 0; foreach (SetAccount el in AccountsList.Children) { DataRow row = tableLoad.Rows[xL]; el.Owner.Text = (string)row["Owner"]; el.filePath.Text = (string)row["Path"]; xL++; } } catch (Exception) { } }
private void deleteButton_Click(object sender, RoutedEventArgs e) { SetAccount elem = (SetAccount)((FrameworkElement)((FrameworkElement)(((FrameworkElement)sender).Parent)).Parent).Parent; AccountsList.Children.Remove(elem); }