我使用WPF的Canvas畫布 要實現擦板的功能,將多個Rectangle疊再一起時,只能觸發最上層的Rectangle 如下圖
請問該如何做出像下圖的功能
public void Image_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
System.Windows.Rect Rect;
RectangleGeometry RectangleGeometry;
DesignerItem DesignerItem = (DesignerItem)sender;
Point MouseScreenPos = new Point();
MouseScreenPos = e.GetPosition(DesignerItem);
if (DesignerItem.Content.ToString() == "System.Windows.Shapes.Rectangle")
{
Rectangle EraserPen = (Rectangle)DesignerItem.Content;
PathGeometry ClipPathGeometry = new PathGeometry();
ClipPathGeometry = (PathGeometry)EraserPen.Clip;
RectangleGeometry = new RectangleGeometry();
Rect = new System.Windows.Rect();
Rect.Width = Rect.Height = 200;
Rect.X = MouseScreenPos.X - 100;
Rect.Y = MouseScreenPos.Y - 100;
RectangleGeometry.Rect = Rect;
EraserPen.Clip = Geometry.Combine(ClipPathGeometry, RectangleGeometry, GeometryCombineMode.Exclude, null);
}
}
}