我有一个WPF应用程序用于动态绘制图表,如下面的代码所示。
public ObservableCollection<KeyValuePair<int, double>> Items { get; set; }
public void startgraph
{
for (i = 0; i < 60; i++)
plot_values[i] = random.NextDouble() * 100;
bw = new BackgroundWorker();
bw.DoWork += (o, ea) =>
{
index = 1;
while (index < 60)
{
this.Dispatcher.BeginInvoke(new Action(() =>
{
Items.Add(new KeyValuePair<int, double>(index++, plot_values[index]));
}));
System.Threading.Thread.Sleep(1000);
}
};
bw.RunWorkerAsync();
}
我想要一个暂停按钮,点击该按钮会暂停该情节,再次点击时会恢复该情节。请帮忙。