Wrong Menu Placement with Zoomed Browser Window

Sep 20, 2010 at 3:57 PM

I find that the menu pops up in the wrong location when the browser window is at any zoom level other than 100%.  This would be the zoom level that you can set in IE, for example, using the pull down menu at the lower right corner of the window.  If you set this to 125%, as an example, the menu pops up fairly far from the control where the mouse click occurs.  The placement gets progressively worse as the zoom level gets farther fro 100%.

Sep 20, 2010 at 4:28 PM
Edited Sep 20, 2010 at 6:12 PM

I know about this issue and I been able to only partly fix it by applying the ApplyZoomTo function on the menu coordinates in the Open method. While this works for first level menus the problem still persists for child menus. Fixing it won't be a piece of cake since several related issues like the HitTest, GetAbsoluteMousePos and IsPointWithinBounds results will have to be dealt with. To make matters worse documentation on this issue is quite sparse. However now that someone has pointed it out I will take another look at it and see what I can do.

Sep 20, 2010 at 7:08 PM
Edited Sep 20, 2010 at 9:10 PM

I have been playing with it and found a solution for my specific case, but I cannot say that it is a proper solution for all the scenarios supported by the control.


In the function

void Open(Point mousePos, Point? offset, int delay, UIElement triggerElement, MouseEventArgs e)

I replaced the calculation for RootGrid.Margin to the following:

Rect rect = ActualTriggerElement.GetBoundsRelativeTo(Application.Current.RootVisual).Value;

RootGrid.Margin = new Thickness(OffsetX + rect.Left + (offset.HasValue ? offset.Value.X : 0), OffsetY + rect.Top + (offset.HasValue ? offset.Value.Y : 0), 0, 0);




The original code was:


RootGrid.Margin = new Thickness(mousePos.X + OffsetX + (offset.HasValue ? offset.Value.X : 0),mousePos.Y + OffsetY + (offset.HasValue ? offset.Value.Y : 0), 0,


There is still a problem with this solution when the menu is configured to pop up when the mouse hovers.  The problem is that the menu disappears soon after you move the mouse onto the popped up area, probably because there is code elsewhere that now thinks the mouse is not over the menu and so dismisses it.  I am still trying to diagnose that one.


Thank You.

Sep 21, 2010 at 3:15 PM

Fixed in the latest change set. Please check it out.

Sep 21, 2010 at 5:30 PM

I received your notification that you have fixed the menu placement problem.  However, I cannot find any new files to download.  The page says “Updated: Sep 14 2010”, however the recommended download is ‘SL4PopupMenyDemo v1.72.zip’ which is the version I downloaded yesterday.  It also says ‘uploaded Sep 7’.  I downloaded the latest changeset (50247) but the problem was not fixed in this changeset.  Are you sure you uploaded the new code? 

Thank You.

Sep 21, 2010 at 6:13 PM
Edited Sep 21, 2010 at 6:21 PM

It is in the source code section of the page. Here is the direct link:


I made the necessary changes in functions GetAbsoluteElementPos and HitTest.

Actually the Popup menu control, on which the PopupMenu relies to show its content, does not take into account the zoom factor when it positions its content elements. I had assumed that all controls should deal with the zooming in the same manner and this is how I got stuck.

Thanks for your post by the way. It gave me some insight on what was really happening.


Sep 21, 2010 at 6:28 PM

Thanks for the quick response.  I downloaded the latest version and I can confirm that the placement problem is resolved.  There seems to be one remaining issue, however.  If you hover over the 'hover item' to produce the popup menu, then attempt to move the mouse over that popup menu, the menu will disappear after a second or two.  I believe the HitTest is saying that the mouse is not over the menu, so it is causing the menu to be closed.  Y

ou can see this in the demo.  If you hover over the hover item, the problem will occur.  If you click the hover item, which also produces the menu, then the problem does not occur.  It seems that whenever you click an item to produce the menu the problem does not occur.

Thanks again for your efforts.

Sep 22, 2010 at 3:29 AM


Sep 22, 2010 at 3:07 PM

Works great! Fantastic.