Looking to learn a way to clean up this code. Is there any way to apply a defined “style” in c#? I am new and looking for ways to tighten up my programming. I would like to be able to define the margin, maximum value, orientation, step frequency, tick frequency, tick placement, and transitions to each slider in a more concise way.
//Slider 1
Slider Slider_1 = new Slider();
Slider_1.SetValue(Grid.ColumnProperty, 0);
Slider_1.Margin = new Thickness(30, 12, 0, 0);
Slider_1.Orientation = Orientation.Vertical;
Slider_1.Maximum = 10;
Slider_1.StepFrequency = 0.25;
Slider_1.TickFrequency = 0.25;
Slider_1.TickPlacement = TickPlacement.Outside;
Slider_1.Transitions = new TransitionCollection();
Slider_1.Transitions.Add(new EntranceThemeTransition() { });
//Slider 2
Slider Slider_2 = new Slider();
Slider_2.SetValue(Grid.ColumnProperty, 1);
Slider_2.Margin = new Thickness(30, 12, 0, 0);
Slider_2.Orientation = Orientation.Vertical;
Slider_2.Maximum = 10;
Slider_2.StepFrequency = 0.25;
Slider_2.TickFrequency = 0.25;
Slider_2.TickPlacement = TickPlacement.Outside;
Slider_2.Transitions = new TransitionCollection();
Slider_2.Transitions.Add(new EntranceThemeTransition() { });
//Slider 3
Slider Slider_3 = new Slider();
Slider_3.SetValue(Grid.ColumnProperty, 2);
Slider_3.Margin = new Thickness(30, 12, 0, 0);
Slider_3.Orientation = Orientation.Vertical;
Slider_3.Maximum = 10;
Slider_3.StepFrequency = 0.25;
Slider_3.TickFrequency = 0.25;
Slider_3.TickPlacement = TickPlacement.Outside;
Slider_3.Transitions = new TransitionCollection();
Slider_3.Transitions.Add(new EntranceThemeTransition() { });
//Slider 4
Slider Slider_4 = new Slider();
Slider_4.SetValue(Grid.ColumnProperty, 3);
Slider_4.Margin = new Thickness(30, 12, 0, 0);
Slider_4.Orientation = Orientation.Vertical;
Slider_4.Maximum = 10;
Slider_4.StepFrequency = 0.25;
Slider_4.TickFrequency = 0.25;
Slider_4.TickPlacement = TickPlacement.Outside;
Slider_4.Transitions = new TransitionCollection();
Slider_4.Transitions.Add(new EntranceThemeTransition() { });
1 Answer