2012-11-07 25 views
5

Çeşitli çizim türleri çizebileceğim bir çizim uygulaması geliştiriyorum. Hat köşe noktalarında bir itemsControl kullanarak bir başparmak yerleştirdim. Kullanıcı, fareyi tıkladığı ve fareyi sürüklediği zaman bu köşe noktasını hareket ettirmelidir. Şu an olan şey şu ki, bunu yaptığımda nokta ve başparmak biraz hareket ediyor, ama sonra fare yakalamayı hemen kaybediyor ve artık hareket etmiyor. Doğru olarak tetiklenen ilk dragdelta olayının hatalarını ayıklamak, gönderen başparmağından itemscontrol öğesine ve ötesine kadar izlenen tam bir görsel ağaç içerir, ancak bazen bir dahaki sefere tetiklendiğinde, başlığın konumu güncellenmemiştir ve içerik barındıran içeriğe sahip değildir. Görsel ağaçta boş ebeveynler var.Thumbs on line köşesi noktaları değiştirmiyor

Tooline hattı

public PointRelocateThumb() 
    { 

     base.DragDelta += new DragDeltaEventHandler(this.PointRelocateThumb_DragDelta); 

    } 
    void PointRelocateThumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) 
    { 
     PointRelocateThumb prt = (PointRelocateThumb)sender; 
     LineCornerPoint lcp = (LineCornerPoint)prt.DataContext; 
     Point thumbPoint = new Point(Canvas.GetLeft((ContentPresenter)prt.TemplatedParent), Canvas.GetTop((ContentPresenter)prt.TemplatedParent)); 
     ToolLine toolLine = null; 
     DrawingCanvas designer = null; 
     ItemsControl itemsControl = ItemsControl.ItemsControlFromItemContainer(prt.TemplatedParent); 
     if (itemsControl != null) 
      toolLine = itemsControl.DataContext as ToolLine; 
     if (toolLine != null) 
      designer = VisualTreeHelper.GetParent(toolLine) as DrawingCanvas; 
     if (toolLine != null && designer != null && toolLine.IsSelected) 
     { 
      thumbPoint = new Point(thumbPoint.X + Canvas.GetLeft(toolLine) + 3.5, thumbPoint.Y + Canvas.GetTop(toolLine) + 3.5); 

      toolLine.undoBounding(); 
      if (System.String.Compare(toolLine.indicator, "BrokenLinkLine") == 0 
       || System.String.Compare(toolLine.indicator, "LinkLine") == 0 
       || System.String.Compare(toolLine.indicator, "OrthogonalLinkLine") == 0 
       || System.String.Compare(toolLine.indicator, "BrokenLine") == 0 
       || System.String.Compare(toolLine.indicator, "Line") == 0 
       || System.String.Compare(toolLine.indicator, "Polygon") == 0) 
      { 
       if (toolLine.pathFigure.StartPoint.Equals(thumbPoint)) 
       { 
        toolLine.pathFigure.StartPoint = new Point(modifyingToolLine.pathFigure.StartPoint.X + e.HorizontalChange, modifyingToolLine.pathFigure.StartPoint.Y + e.VerticalChange);     } 
       else 
       { 
        foreach (LineSegment ls in toolLine.pathSegmentCollection) 

        { 
         if (ls.Point.Equals(thumbPoint)) 
         { 
          ls.Point = new Point(ls.Point.X + e.HorizontalChange, ls.Point.Y + e.VerticalChange); 
          break; 
         } 

        } 
       } 
      } 
      toolLine.regenerateBoundingItem(); 
     } 
     e.Handled = true; 
    } 
} 

} PointRelocateThumb için

<ItemsControl x:Name="PART_LineRelocate" ItemsSource="{Binding pointsObservableCollection}" Visibility="Collapsed" > 
    <ItemsControl.ItemTemplate> 
     <DataTemplate DataType="{x:Type s:LineCornerPoint}" > 
      <Grid> 
       <c:PointRelocateThumb VerticalAlignment="Center" HorizontalAlignment="Center" Focusable="True" x:Name="PART_PointRelocateThumb" Cursor="Hand"/> 
      </Grid> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <Canvas IsItemsHost="True" /> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
    <ItemsControl.ItemContainerStyle > 
     <Style > 
      <Style.Triggers> 
        <DataTrigger Value="BrokenLinkLine" Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type s:ToolLine}}, Path=indicator}" > 
         <Setter Property="Canvas.Left" Value="{Binding Corner.X}" /> 
         <Setter Property="Canvas.Top" Value="{Binding Corner.Y}" /> 
        </DataTrigger> 

        ....More of these datatriggers for the different types of lines 
       </Style.Triggers> 
     </Style> 
    </ItemsControl.ItemContainerStyle> 

kodu:

Bu

hattı başparmak noktalarına ilişkin xaml kısmıdır sınıf. Bağlanmayı geri almanın nedeni, toolLine'ın Canvas.Left ve Canvas.Top'un 0'a ayarlanmasını, ancak noktaları aynı noktada bulunacak şekilde ölçeklendirmesidir - yani eski Canvas.Left ve Canvas ekleyerek. Takımın satırdaki her noktaya üst değerleri.

öğeyi Sınırlama yenilenmesi için kod

aşağıdaki gibidir:

public void regenerateBoundingItem() 
{ 
    //Following line of code just regenerates the underlying path for the toolLine from the 
    //new pathsegmentCollection and pathFigure start point. 
    regenerateThisLine(); 
    double leftMostPoint = double.MaxValue, topMostPoint = double.MaxValue, bottomMostPoint = double.MinValue, rightMostPoint = double.MinValue; 
    getBoundingPoints(ref leftMostPoint, ref topMostPoint, ref bottomMostPoint, ref rightMostPoint); 

    //subtracts leftMost point and topMostPoint from each point in the line 
    scaleLinePoints(leftMostPoint, topMostPoint); 
    Canvas.SetLeft(this, leftMostPoint); 
    Canvas.SetTop(this, topMostPoint); 
    this.Width = rightMostPoint - leftMostPoint; 
    this.Height = bottomMostPoint-topMostPoint; 
     regenerateObservableCollection(); 
     regenerateThisLine(); 
} 
private void regenerateObservableCollection() 
{ 
    if (this.pointsObservableCollection == null) 
     this.pointsObservableCollection = new ObservableCollection<LineCornerPoint>(); 
    this.pointsObservableCollection.Clear(); 
    LineCornerPoint startPt = new LineCornerPoint(new Point(this.pathFigure.StartPoint.X - 3.5, this.pathFigure.StartPoint.Y - 3.5)); 
    this.pointsObservableCollection.Add(startPt); 
    if (System.String.Compare(indicator, "BrokenLine") == 0 
     || System.String.Compare(indicator, "BrokenLinkLine") == 0 
     || System.String.Compare(indicator, "LinkLine") == 0 
     || System.String.Compare(indicator, "Polygon") == 0 
     || System.String.Compare(indicator, "Line") == 0) 
    { 
     foreach (LineSegment ls in pathSegmentCollection) 
     { 
      LineCornerPoint pt = new LineCornerPoint(new Point(ls.Point.X - 3.5, ls.Point.Y - 3.5)); 
      this.pointsObservableCollection.Add(pt); 
     } 
    } 
} 

PointRelocateThumb için şablon genişliği ve yüksekliği 7 bir elips - ı 3.5 oranında bütün başparmak yerleri ofset zorunda açıklar.

cevap

0

sorun regenerateObserableCollection

yerine temizleme ve tüm LineCornerObjects yok oldu, ben de gözlemlenebilir koleksiyonda yer alan LineCornerPoints değiştirmek zorunda kaldı.