have tested this, it worked, at least for me

WPF 碰撞检测

var x1 = Canvas.GetLeft(e1);
var y1 = Canvas.GetTop(e1);
Rect r1 = new Rect(x1, y1, e1.ActualWidth, e1.ActualHeight);


var x2 = Canvas.GetLeft(e2);
var y2 = Canvas.GetTop(e2);
Rect r2 = new Rect(x2, y2, e2.ActualWidth, e2.ActualHeight);

if (r1.IntersectsWith(r2))
    MessageBox.Show("Intersected!");
else
    MessageBox.Show("Non-Intersected!");

 

 

ar ellipse1Geom = ellipse1.RenderedGeometry;
var ellipse2Geom = ellipse2.RenderedGeometry;
var detail = ellipse1Geom.FillContainsWithDetail(ellipse2Geom);
if(detail != IntersectionDetail.Empty)
{
    // We have an intersection or one contained inside the other
}

The Geometry.FillContainsWithDetail(Geometry) method is defined as

Returns a value that describes the intersection between the current geometry and the specified geometry.

相关文章:

  • 2022-12-23
  • 2022-01-05
  • 2022-01-05
  • 2021-08-14
  • 2021-08-14
  • 2021-12-18
  • 2021-09-28
猜你喜欢
  • 2021-06-01
  • 2021-07-26
  • 2022-01-05
相关资源
相似解决方案