我有一个画布,可以在其上进行徒手画(类似于http://www.windowsphonegeek.com/tips/drawing-in-wp7-2-drawing-shapes-with-finger)。我的要求是,我必须使绘图播放和暂停programaticaly。有按钮,点击图纸应该按照绘制的方式播放。如果有任何示例应用程序或链接可用,请指导我应采取哪些步骤来实现此目的。感谢。
答案 0 :(得分:0)
更新:我终于解决了这个问题,因此它适用于Windows Phone 7,而不仅仅是WPF。
基于您引用的示例。
定义点列表:
private List<Point> _points;
当LeftMouseButton为Down AND Up时,添加一个空白点和起点:
oldPoint = currentPoint;
_points.Add(new Point(-1, -1));
_points.Add(oldPoint);
您的播放按钮事件处理程序将如下所示:
canvas.Children.Clear();
// Use the BackgroundWorker to draw the lines
BackgroundWorker worker = new BackgroundWorker();
worker.WorkerReportsProgress = true;
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.RunWorkerAsync();
worker_DoWork遍历_points并将它们发送给我们的调度员:
void worker_DoWork(object sender, DoWorkEventArgs e)
{
for (int ix = 0; ix < _points.Count - 1; ix++)
{
Point start = _points[ix];
Point end = _points[ix + 1];
if (start.X == -1 || end.X == -1)
continue;
Thread.Sleep(10);
DoEvents(start, end);
}
}
DoEvents使用Dispatcher
将行坐标发送到委托方法
private delegate void AddLineDelegate(Point p1, Point p2);
private void DoEvents(Point p1, Point p2)
{
this.Dispatcher.BeginInvoke(new AddLineDelegate(AddLine), new object[] { p1, p2 });
}
private void AddLine(Point p1, Point p2)
{
Line line = new Line() { X1 = p1.X, Y1 = p1.Y, X2 = p2.X, Y2 = p2.Y };
line.Stroke = new SolidColorBrush(Colors.Black);
line.StrokeThickness = 4;
this.canvas.Children.Add(line);
}