다양한 유형의 선을 그릴 수있는 그리기 응용 프로그램을 개발 중입니다. 라인 모서리 점에서 itemsControl을 사용하여 엄지 손가락을 배치했습니다. 엄지 손가락은 사용자가 마우스를 클릭하고 마우스를 끌 때 그 꼭지점을 움직여야합니다. 현재이 일을 할 때 점과 엄지가 약간 움직이면 바로 마우스 캡처가 사라지고 더 이상 움직이지 않는다는 것입니다. 올바르게 발사 된 첫 번째 dragdelta 이벤트를 디버깅 할 때 보내기 엄지 손가락에서 itemscontrol 이상까지 추적되는 전체 시각적 트리가 있지만 다음에 실행될 때 엄지 위치가 업데이트되지 않고 포함 된 컨텐트 발표자 시각 트리에서 부모가 널입니다.라인 모서리 점의 엄지 손가락이 점의 위치를 변경하지 않습니다
Tooline는 라인
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위한
<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>
코드 :
이
라인 엄지 점 관련된 XAML의 일부인 수업. 바인딩을 취소하는 것은 toolLine이 Canvas.Left와 Canvas.Top을 0으로 설정하지만 포인트가 여전히 같은 지점에 위치하도록 (즉, 이전 Canvas.Left와 Canvas를 추가하여) toollines에 조정되도록하는 것입니다. line의 각 점에 대한 toolLine의 최고 값.항목 경계 중생의 코드
은 다음과 같습니다 :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 모든 엄지 손가락의 위치를 상쇄하는 이유에 대해 설명합니다.