ScrollBar,Slider,ProgressBar继承自RangeBase,RangeBase继承自Control
RangeBase类属性
value控件的当前值默认为0,双精度浮点数,value发生变化时响应ValueChanged事件
Maximum 上限
Minimum 下限
SmallChange 上下调整数量小变化
LargeChange 上下调整数量大变化
一、ScrollBar
滚动条
ScrollViewer 封装了两个ScrollBar
二、Slider
<Slider Width="300" Value="50" Minimum="0" Maximum="200"></Slider>
//水平条还是垂直条,默认水平 //slider.Orientation = Orientation.Vertical; //刻度 slider.TickPlacement = TickPlacement.TopLeft; //刻度间隔 slider.TickFrequency = 10; //只显示该集合内的刻度 //slider.Ticks = new DoubleCollection() { 1, 10, 20, 30, 40, 50 }; //自动跳转到最近的刻度上 slider.IsSnapToTickEnabled = true; //结合SelectionStart,SelectionEnd设置范围阴影 slider.IsSelectionRangeEnabled = true; slider.SelectionStart = 30; slider.SelectionEnd = 60;
滑动事件
slider.ValueChanged += slider_ValueChanged;
private void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) { lable.Content = slider.Value; }
public MainWindow() { InitializeComponent(); //水平条还是垂直条,默认水平 //slider.Orientation = Orientation.Vertical; //刻度 slider.TickPlacement = TickPlacement.TopLeft; //刻度间隔 slider.TickFrequency = 10; //只显示该集合内的刻度 //slider.Ticks = new DoubleCollection() { 1, 10, 20, 30, 40, 50 }; //自动跳转到最近的刻度上 slider.IsSnapToTickEnabled = true; //结合SelectionStart,SelectionEnd设置范围阴影 slider.IsSelectionRangeEnabled = true; slider.SelectionStart = 30; slider.SelectionEnd = 60; slider.ValueChanged += slider_ValueChanged; } private void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) { lable.Content = slider.Value; }
三、ProgressBar
<ProgressBar Name="progressBar" Width="120" Value="50" Minimum="0" Maximum="200" Height="30"></ProgressBar>
//一个小绿条从左向右移动 progressBar.IsIndeterminate = true;