private void checkboxFactory(GearAttribute currentAttribute) { CheckBox generatedChk = new CheckBox() { Foreground = DivisionOrange, Name = String.Format("chkAttribute_{0}", currentAttribute.AttributeName.Replace(" ", String.Empty)).Replace("/", ""), Content = currentAttribute.AttributeName, DataContext = currentAttribute }; generatedChk.Checked += chkGenerated_Checked; generatedChk.Unchecked += chkGenerated_Checked; wpChkAttributes.Children.Add(generatedChk); }
private void chkGenerated_Checked(object sender, RoutedEventArgs e) { GearAttribute checkedAttribute = (GearAttribute)((CheckBox)sender).DataContext; StackPanel spDescription = new StackPanel() { Name = String.Format("spDescription_{0}", checkedAttribute.AttributeName.Replace(" ", String.Empty).Replace("/", String.Empty)), Orientation = Orientation.Horizontal }; Label lblDescription = new Label() {//Montserrat SemiBold Name = String.Format("lblDescription_{0}", checkedAttribute.AttributeName.Replace(" ", String.Empty).Replace("/", String.Empty)), Content = String.Format("{0}: {1}-{2}", checkedAttribute.AttributeName, checkedAttribute.minRoll, (chkIsGearSet.IsChecked == true) ? checkedAttribute.setMaxRoll : checkedAttribute.maxRoll), Foreground = DivisionOrange, HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom, FontFamily = new FontFamily("Montserrat SemiBold") }; TextBox txtAttributeInput = new TextBox() { Name = String.Format("txtAttributeInput_{0}", checkedAttribute.AttributeName.Replace(" ", String.Empty).Replace("/", String.Empty)), Text = String.Empty, Height = 18, Width = 75, Margin = new Thickness(10, 0, 5, 0), HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Center, FontFamily = new FontFamily("Montserrat") }; txtAttributeInput.PreviewTextInput += textbox_PreviewTextInput; StackPanel spPercentile = new StackPanel() { Orientation = Orientation.Vertical, Height = 30, Width = 75, Margin = new Thickness(0, 0, 0, 5), VerticalAlignment = VerticalAlignment.Center, IsEnabled = false, Visibility = Visibility.Collapsed }; Label lblPercentileVal = new Label() { Content = "0%", Foreground = Brushes.White, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom, FontSize = 10, FontFamily = new FontFamily("Montserrat") }; ProgressBar pbPercentile = new ProgressBar() { Height = 5, Width = 75, Background = Brushes.Transparent, Foreground = Brushes.White, Margin = new Thickness(0, -2, 0, 5) }; /* * <StackPanel Orientation="Verticle" Height="30" Width="75" Margin="0,0,0,5" VerticleAlignment="Center" isEnabled="false"> * <Label Content="0%" /> * <ProgressBar Height="5" Width="75" /> * </StackPanel> */ spPercentile.Children.Add(lblPercentileVal); spPercentile.Children.Add(pbPercentile); spDescription.Children.Add(lblDescription); spDescription.Children.Add(txtAttributeInput); spDescription.Children.Add(spPercentile); if (((CheckBox)sender).IsChecked == true) { wpAttributeDesc.Children.Add(spDescription); btnCalculatePercentile_Gear.IsEnabled = true; btnCalculatePercentile_Gear.Visibility = Visibility.Visible; btnClearPercentile_Gear.IsEnabled = true; btnClearPercentile_Gear.Visibility = Visibility.Visible; } else if (((CheckBox)sender).IsChecked == false) { for (int index = 0; index < wpAttributeDesc.Children.Count; index++) { if (((StackPanel)wpAttributeDesc.Children[index]).Name == spDescription.Name) { wpAttributeDesc.Children.RemoveAt(index); } } if (wpAttributeDesc.Children.Count == 0) { btnClearPercentile_Gear.IsEnabled = false; btnCalculatePercentile_Gear.IsEnabled = false; btnClearPercentile_Gear.Visibility = Visibility.Collapsed; btnCalculatePercentile_Gear.Visibility = Visibility.Collapsed; } } }