我正在尝试为我现有的多边形绘图的重绘功能生成一个线程。我在这里读到有可能 UI 可以在线程中实现,请参见此处的链接,但我不能在我的 redrawSingelPoly() 函数上使用它......有什么想法可以将 redrawSingelPoly() 用作线程吗?
在我的 MainWindow.xaml.cs 中:
当用户按下我的主窗口上的按钮时调用:
private void SingleSelectedMeasurement(object sender, RoutedEventArgs e)
{
System.Windows.Controls.Button button = (System.Windows.Controls.Button)sender;
RedrawSingelMeasurement(Convert.ToInt16(button.Tag));
}
private void RedrawSingelMeasurement(int selectedMeasurement)
{
selectedMeasurement = selectedMeasurement - 1;
for (int i = 0; i < measurements.Length; i++)
{
if (selectedMeasurement != i)
{
measurements[i].draw = false; //block drawing
}
else
{
measurements[i].draw = true; // remove block for drawing
}
}
measurements[selectedMeasurement].redrawSingelPoly();
}
在我的 Measurement.cs 中:
public void redrawSingelPoly()
{
Polyline poly = new Polyline();
poly.Stroke = colorBrush;
poly.StrokeThickness = basicLineThick;
//first clean all
coordinateSystem.Children.Clear();
poly.Points = points;
//draw
coordinateSystem.Children.Add(poly);
}