private void SessionTypeClick(object sender, RoutedEventArgs e) { Session_types session_type = (Session_types)((Button)sender).DataContext; deleteSessionTypeButton.Visibility = Visibility.Visible; changeSessionTypeButton.Visibility = Visibility.Visible; sessionTypeName.Text = session_type.session_type; this.session_type = session_type; this.sessionTypeButton = (Button)sender; }
private void CreateSessionTypeClick(object sender, RoutedEventArgs e) { Session_types type = new Session_types(); type.session_type = sessionTypeName.Text; int i = -1; bool isFindId = true; while (isFindId) { i++; isFindId = false; foreach (Session_types session_type in main.bd.Session_types) { if (session_type.id == i) { isFindId = true; } } } type.id = i; main.bd.Session_types.Add(type); main.bd.SaveChanges(); Button button = new Button(); button.Content = type.session_type; button.FontSize = 15; button.Click += SessionTypeClick; button.DataContext = type; sessionTypes.Children.Add(button); ComboBoxItem item = new ComboBoxItem(); item.Content = type.session_type; item.DataContext = type; sessionType.Items.Add(item); }