希望学习一种清理此代码的方法。有没有办法在 c# 中应用定义的“样式”?我是新手,正在寻找方法来加强我的编程。我希望能够以更简洁的方式定义边距、最大值、方向、步进频率、滴答频率、滴答位置以及到每个滑块的过渡。
//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() { });