내 wpf 응용 프로그램에서 캔버스에 선을 업데이트 (시작점, 끝점 좌표 변경)하고 변경 사항을 미리보고 싶습니다. 문제는 내가 줄을 추가하지만 초기 상태와 최종 상태 만 볼 수 있다는 것입니다.WPF 캔버스를 정말 빨리 업데이트하는 방법은 무엇입니까?
라인/캔버스 자체를 실시간으로 업데이트하는 방법이 있습니까? 선의 길이/위치가 어떻게 변하는 지보고 싶습니다.
예를 들어, 행의 시작/끝 쌍 목록을 수신합니다. 목록을 반복하고 쌍의 값이있는 행의 좌표를 업데이트하면 중간 상태를 볼 수 없습니다.
나는 라인과 캔버스의 가시성을 볼 수 있도록 설정하여 강제 업데이트하려고했지만 작동하지 않습니다. 만약 내가 새로운 라인을 추가한다면, 나는 그것이 어떻게 추가되는지를 볼 수 없으며 단지 마지막 단계이다.
아래 코드에서 DrawLine 메서드는 새로운 점이있을 때마다 루프에서 호출됩니다.
제안 사항? 한 번에 모든 변경 사항을 적용 UI 스레드에서 루프를 통해 실행 한 다음 마지막으로 렌더러가에서 기회를 얻을 수 있도록
public void DrawLine(List<Library2d.Point> points)
{
PathFigure myPathFigure = new PathFigure();
myPathFigure.StartPoint = new System.Windows.Point(points.ElementAt(0).X, points.ElementAt(0).Y);
LineSegment myLineSegment = new LineSegment();
myLineSegment.Point = new System.Windows.Point(points.ElementAt(1).X, points.ElementAt(1).Y);
PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
myPathSegmentCollection.Add(myLineSegment);
myPathFigure.Segments = myPathSegmentCollection;
PathFigureCollection myPathFigureCollection = new PathFigureCollection();
myPathFigureCollection.Add(myPathFigure);
PathGeometry myPathGeometry = new PathGeometry();
myPathGeometry.Figures = myPathFigureCollection;
if (myPath == null)
{
myPath = new Path();
myPath.Stroke = Brushes.ForestGreen;
myPath.StrokeThickness = 1;
canvas.Children.Add(myPath);
}
myPath.Data = myPathGeometry;
myPath.Visibility = Visibility.Visible;
myPath.InvalidateMeasure();
canvas.Visibility = Visibility.Visible;
canvas.InvalidateMeasure();
}