首先时间轴使用slider控件,得到如图效果
代码如下:
<Grid Grid.Row="2">
<StackPanel VerticalAlignment="Center" Margin="10">
<Slider x:Name="SliderName" Maximum="16" TickPlacement="TopLeft" TickFrequency="1" IsSnapToTickEnabled="True" ValueChanged="Slider_ValueChanged" IsMoveToPointEnabled="True" />
</StackPanel>
</Grid>
后台可以操作这个Slider_ValueChanged事件,这样就会产生拖动效果。
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
Date showTime=null;
string sliderValue = (this.SliderName.Value+7).ToString();
//将时间改为字符串类型
if (this.SliderName.Value < 3)
{
dateStr = dateStr + " 0" + sliderValue + ":00:00";
}
else
{
dateStr = dateStr + " " + sliderValue + ":00:00";
}
showTime = Convert.ToDateTime(dateStr);
//这个方法内负责查询
QueryData(showTime);
}