WPF不能从工具箱中拖Timer控件,需引用线程类 using System.Windows.Threading;
声明Timer
private DispatcherTimer timer=new DispatcherTimer();
//WPF没有Timer控件,用DispatcherTimer实现Timer功能
给Timer控件添加事件(工作内容),循环时间
timer.Interval = new TimeSpan(0, 0, 1);//时间间隔为一秒
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
/// <summary>
/// Timer控件工作内容
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void timer_Tick(object sender, EventArgs e)
{
//绘制波形图(横纵坐标范围确定:横坐标起始频率;纵坐标从得到的值中获得最大最小值)
_viewModel = new PlotViewModle();
//画直线
this.DataContext = _viewModel;
}