Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7901197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:09:37+00:00 2026-06-03T09:09:37+00:00

I have a DrawingVisual element that rappresents a path which geometry is described by

  • 0

I have a DrawingVisual element that rappresents a path which geometry is described by this syntax:

“m106,59.3c0-1.98,0,0-4.95,0.989-3.96,0.989-13.8,3.96-20.8,4.95-6.92,0-14.8-3.96-17.8-3.96-1.98,2.97,3.96,10.9,7.91,13.8,2.97,1.98,9.89,3.96,14.8,3.96,4.95-0.989,10.9-2.97,13.8-6.92,2.97-2.97,5.93-10.9,6.92-12.9z”

To render the visual i use MyCanvas class, that provides hit-testing functionality:

public class MyCanvas : Panel
{
   public List<Visual> Visuals = new List<Visual>();
   private List<DrawingVisual> Hits = new List<DrawingVisual>();

   public void AddVisual(Visual Visual)
   {
       this.Visuals.Add(Visual);
       base.AddVisualChild(Visual);
       base.AddLogicalChild(Visual);
   }

   public List<DrawingVisual> GetVisuals(Geometry Region)
   {
       GeometryHitTestParameters Parameters = new GeometryHitTestParameters(Region);
       this.Hits.Clear();
       HitTestResultCallback Callback = new HitTestResultCallback(this.HitTestCallBack);
       VisualTreeHelper.HitTest(this, null, Callback, Parameters);

       return this.Hits;
   }

   private HitTestResultBehavior HitTestCallBack(HitTestResult Result)
   {
        GeometryHitTestResult GeometryRes = (GeometryHitTestResult)Result;
        DrawingVisual DVisual = Result.VisualHit as DrawingVisual;

        if (DVisual != null && GeometryRes.IntersectionDetail == IntersectionDetail.FullyInside) 
            this.Hits.Add(DVisual);     

       return HitTestResultBehavior.Continue;
   }

   protected override Visual GetVisualChild(int Index)
   { return this.Visuals[Index]; }

   protected override int VisualChildrenCount {
        get { return this.Visuals.Count; }
   }
}

When i draw my (red) path this is the result:

Where the size of the grid cells is 50×50. Now i try to get visuals for example in this region:

MyCanvas my_canvas = new MyCanvas();
RectangleGeometry MyRegion = new RectangleGeometry(new Rect(50, 50, 250, 250));
DrawingVisual MyPath = new DrawingVisual();

using (DrawingContext context = MyPath.RenderOpen()) {
   context.PushTransform(new TranslateTransform(50, 50));
   context.PushTransform(new ScaleTransform(2, 2));
   context.DrawGeometry(Brushes.Red, new Pen(), MyGeometry);
}

my_canvas.AddVisual(MyPath);
List<DrawingVisual> result = my_canvas.GetVisuals(MyRegion);

But MyPath is not in result, why? How i have to properly do hit-test?
Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:09:38+00:00Added an answer on June 3, 2026 at 9:09 am

    It seems like hit-testing considers the position of the shapes to which was applied a reverse order of transformations. This would explain why my path is intersected only and not fully inside the RectangleGeometry argument of MyCanvas.GetVisuals method.

    Waiting for a better response, i implemented the hit-test with a not hit-testing method, now part of MyCanvas class:

    public List<DrawingVisual> GetVisuals(Rect Area)
    {
       this.Hits.Clear();
    
       foreach (DrawingVisual DVisual in this.Visuals) {
           if (Area.Contains(DVisual.DescendantBounds))
               this.Hits.Add(DVisual);
       }
    
       return this.Hits;
    }
    

    EDIT:

    As Mike Danes (moderator on MSDN forum) explains in this thread:

    "Is it really possible that this is a bug in geometry hit-testing?"

    I’m 99% sure this is a bug. Drawing and hit testing should use the same transform order. The reason it works correctly with TransformGroup is because this way you only push only one transform in the drawing context and this avoids the wrong multiplication order in the hit test drawing context.
    Note that this has nothing to do with the fact that the order used in TranformGroup is different from the push order.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that inherits from DrawingVisual. It declares a DependencyProperty which, when
Have some dates in my local Oracle 11g database that are in this format:
I have a DrawingVisual object I have created for example using this method: Private
Have data that has this kind of structure. Will be in ascending order by
Have data that has this kind of structure: $input = [ { animal: 'cat',
Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css
Have a SomeLib.pro file that contains: CONFIG += debug TEMPLATE = lib TARGET =
Have a matrix report now that has Position, Hours and Wages for a location
Have converted devise new session from erb to Haml but doens't work, this is
have Googled the cr*p out of this one so apologies if the answer is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.