2012-11-07 16 views
5

स्थानांतरित नहीं करते हैं मैं एक ड्राइंग एप्लिकेशन विकसित कर रहा हूं जिसमें कोई भी विभिन्न प्रकार की रेखाएं खींच सकता है। लाइन कोने पॉइंट्स पर मैंने आइटम्स कंट्रोल का उपयोग करके अंगूठे रखा है। अंगूठे को उस कोने बिंदु को स्थानांतरित करना चाहिए जब उपयोगकर्ता ने माउस पर क्लिक किया और माउस को ड्रैग किया। अब क्या हो रहा है कि जब मैं ऐसा करता हूं तो बिंदु और अंगूठे थोड़ा आगे बढ़ते हैं, लेकिन फिर यह माउस कैप्चर को तुरंत खो देता है और अब आगे नहीं बढ़ता है। जब मैं पहली ड्रैगडेल्टा घटना को डीबग करता हूं जिसे सही ढंग से निकाल दिया जाता है, तो एक पूर्ण दृश्य पेड़ होता है जो भेजने के अंगूठे से आइटम्स कंट्रोल और उससे आगे तक होता है, लेकिन कभी-कभी जब यह अगली बार आग लग जाता है, तो अंगूठे का स्थान अपडेट नहीं किया गया है, और इसमें सामग्री प्रस्तुतकर्ता दृश्य पेड़ में शून्य माता-पिता हैं।लाइन कोने पॉइंट्स पर अंगूठे अंक

<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> 

PointRelocateThumb के लिए कोड:

इस लाइन अंगूठा से संबंधित XAML का हिस्सा होता है

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; 
    } 
} 

}

Tooline रेखा है कक्षा। पूर्ववत बाध्यकारी क्या करता है यह यह बनाता है कि टूललाइन में कैनवास है। लिफ्ट और कैनवास। 0 पर सेट करें, लेकिन अंक को स्केल करें ताकि वे अभी भी एक ही बिंदु पर स्थित हों - यानी पुराने कैनवास। लिफ्ट और कैनवास जोड़कर। टूल के शीर्ष मान लाइन में प्रत्येक बिंदु परलाइन करें।

पुनर्जन्म आइटम Bounding के लिए कोड के नीचे है:

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 के लिए टेम्पलेट चौड़ाई और ऊंचाई 7 की एक अंडाकार है - जो बताता है कि क्यों मैं 3.5 से सभी अंगूठे स्थानों की भरपाई के लिए किया है।

उत्तर

0

समस्या regenerateObserableCollection

समाशोधन के बजाय और सभी LineCornerObjects को नष्ट करने के साथ था, मैं LineCornerPoints नमूदार संग्रह में निहित संशोधित करने के लिए किया था।

संबंधित मुद्दे