Skip to main content

Microsoft Silverlight

Answered Question UIElement.HitTest behaviorRSS Feed

(0)

NDRiley
NDRiley

Member

Member

21 points

13 Posts

UIElement.HitTest behavior

HitTest only appears to work for me using screen coordinates rather than local coordinates (unlike VisualTreeHelper.HitTest). Based on the documentation, this doesn't seem to be the expected behavior. Can anyone please confirm this is a bug?

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Re: UIElement.HitTest behavior

Hello, this is by design. In which document do you find this is not the expected behavior? Here're some comments from our developer team:

For the Rect case, this brings a problem. If our UIElment has say a 45deg rotation, then our Rect in VisualRoot space becomes a trapezoid/rhombus - and the problem with that is that the Rect hittesting code assumes an axis aligned rectangle.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

NDRiley
NDRiley

Member

Member

21 points

13 Posts

Re: UIElement.HitTest behavior

I was referring to the Point case, I would’ve been more specific, but since WPF doesn’t have a Rect HitTest, I didn’t notice that Silverlight did. (Is Silverlight still intended to be a subset of WPF?)

Anyway,  I take the reference below as meaning the coordinate system of UIElement.

Furthermore, the reference to VisualTreeHelper implies the same behavour

 

UIElement..::.HitTest Method (Point)

Parameters

point Type: System.Windows..::.Point

The point in the coordinate system where the hit test is to be performed

Remarks

Typically the point value would be obtained through a mouse event.In WPF, this method exists on the VisualTreeHelper class. Silverlight implements several Visual-related APIs on the UIElement class instead.

 

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

Re: Re: UIElement.HitTest behavior

Well, the document is quite unclear. Actually the coordinate system it talks about should be the global coordinate system. That is the desired behavior. You can easily obtain the point in the global coordinate system.

e.GetPosition(rootElement);

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities