0
저는 캔버스에 GraphNodes를 그려서 캔버스에 ContentControls로 추가합니다. 모든 그래프 노드는 노드에서 다른 노드로 연결 선을 그리는 데 사용하는 adorner를가집니다.WPF 마우스 위치에서 시각적으로 가져 오기
protected override void OnMouseUp(System.Windows.Input.MouseButtonEventArgs e)
{
var SourceNode = AdornedElement;
Point pt = PointToScreen(Mouse.GetPosition(this));
var DestinationNode = ???
}
내가 초기 GraphNode입니다 AdornedElement에서의 선을 그어야하기 시작 곳에서 소스 노드가이 시점에서 다음 adorner는 방법 onMouseUp에 있습니다. 또한 마우스를 놓은 좌표가 있습니다. 이 시점에서 또 다른 GraphNode가 있습니다. 이 시점에 해당하는 노드를 찾는 방법은 무엇입니까?
감사합니다.
protected override void OnMouseUp(System.Windows.Input.MouseButtonEventArgs e)
{
Point pt = PointToScreen(Mouse.GetPosition(this));
UIElement canvas = LogicalTreeHelper.GetParent(AdornedElement) as UIElement;
// This is important to get the mouse position relative to the canvas, otherwise it won't work
pt = canvas.PointFromScreen(pt);
VisualTreeHelper.HitTest(canvas, null, HitTestResultCallbackHandler, new PointHitTestParameters(pt));
}
를, 그리고, 그러나 hitTest 방법은 GraphNode를 찾을 수 :
합니까 [e.OriginalSource] (http://msdn.microsoft.com/en-us/library/system.windows.routedeventargs.originalsource.aspx) 또는 [e.Source] (HTTP : // msdn.microsoft.com/en-us/library/system.windows.routedeventargs.source.aspx) help? – LPL
아니요 항상 소스 인 AdornedElement입니다. MouseUpEvent를 생성하는 대상 노드를 찾고 싶습니다. – alexandrudicu
그런 다음 여기를 살펴보십시오. [Visual Layer에서의 히트 테스트] (http://msdn.microsoft.com/en-us/library/ms752097.aspx) – LPL