2010-07-23 5 views
0

두 개의 점 사이에 간단한 선을 그리는 셰이프로부터 상속 된 LineG 클래스가 있습니다. 두 개의 종속성 속성 인 StartPointProperty 및 EndPointProperty를 추가하여 간단하게 추가했습니다. 마지막으로 다른 점을 추가하고 싶습니다. 기능은 MidPoint이므로 선을 그릴 때 선의 중간에 중간 점이 생깁니다. 내가 시작점 또는 엔드 포인트 모양이 다시 그려됩니다 끌어, 나는 중간 점을 드래그하면 모양이 ... 중간 지점 변화에 따라 이러한 경우재귀 적 종속성 속성을 피하는 방법

private static void PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
     { 
      LineG lineG = (LineG)d; 
      if (e.Property.Name == "StartPoint") 
      { 

      } 
      else if (e.Property.Name == "EndPoint") 
      { 

      } 
      else //if MidPoint 
      { 
       Point p1 = (Point)e.OldValue; 
       Point p2 = (Point)e.NewValue; 
       double offsetX = p2.X - p1.X; 
       double offsetY = p2.Y - p1.Y; 

       lineG.StartPoint = new Point(lineG.StartPoint.X + offsetX, lineG.StartPoint.Y + offsetY); 
       lineG.EndPoint = new Point(lineG.EndPoint.X + offsetX, lineG.EndPoint.Y + offsetY); 
       lineG.MidPoint = GeneralMethods.MidPoint(lineG.StartPoint, lineG.EndPoint); 
      } 

      lineG.InvalidateMeasure(); 
     } 

protected override Geometry DefiningGeometry 
     { 
      get 
      { 
       lg.StartPoint = StartPoint; 
       lg.EndPoint = EndPoint; 
       return lg; 
      } 
     } 
+1

무엇이 문제입니까? 그리고 제목이 질문의 텍스트와 어떻게 관련되어 있는지 보지 못했습니다 ... –

+0

정말 미안 해요, 정말 두통이 있었어요. 내 질문은 StartPoint 또는 EndPoint를 변경하면 MidPoint와 함께 ... MidPoint를 변경하면 StartPoint와 EndPoint를 모두 변경해야하지만 재귀 적 상황이됩니다 ... StartPoint를 변경하면 MidPoint가 변경되고 MidPoint가 변경됩니다 StartPoint 등등 ...이 문제를 해결하는 방법 ... –

답변

1

을 번역 할 때 당신은 각각의 int 카운터를 추가 할 수 있습니다 처리 중에 증가하는 클래스의 조작. 카운터가 0이 아닌 경우 무언가를하지 마십시오. 예 :

 
private int _suspendCalculation; 

private static void OnPropertyChanged(..) 
{ 
    if (_suspendCalculation > 0) return; 
    _suspendCalculation++; 
    try 
    { 
     CalculateAndSetOtherProperty(); 
    } 
    finally 
    { 
     _suspendCalculation--; 
    } 
}