2011-03-24 4 views
1

내 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(); 
} 

답변

2

렌더링 스레드는 UI 스레드보다 낮은 디스패처 우선 순위를 가지고있다.

데이터 요소에 선을 바인딩하고 대신 업데이트해야합니다. 다음은 다각형을 위해이를 수행하는 방법에 대한 기사입니다 : http://bea.stollnitz.com/blog/?p=35 여러분의 요구에 맞게 조정할 수 있습니다.

관련 문제