How to get the position of the PopupMenu

Feb 22, 2012 at 5:54 AM

Nice menu that meet my needs. Thank you.

I got a question, how to get the position of Popup Menu?  I mean the Top  Left coordinate of the menu?

Sorry if it is a newbie question that posted somewhere?




Feb 24, 2012 at 4:50 PM

This is a good question actually since this information is not accessible right away.

You'll get the position by accessing the margin of the root control for the menu content ContentRoot as such: 

var position = pm.ContentRoot.Margin;

Thanks for asking...I'll definitely make this more obvious in later versions.

Feb 24, 2012 at 5:26 PM

Thank for your response.

If we use MVVM model and want to use an ICommand. how can we have this info in the View (XAML) and then pass to the command in the CommandParameter?

Well, don't want to use code behind.


Thank again for a nice menu.



Feb 24, 2012 at 5:52 PM
Edited Feb 24, 2012 at 6:05 PM

Have you downloaded the source code version of the menu?

If so I suggest you add the required property to the PopupMenuBase class as follows:

public bool Position
    set{SetValue(PositionProperty, value);}

public static readonly DependencyPropertyPositionProperty = DependencyProperty.Register("Position", typeof(bool), typeof(PopupMenuBase), new PropertyMetadata(false, (sender, e)=>
    var pmb = sender as PopupMenuBase;
    return pmb.ContentRoot.Margin;

This should make it accessible from within your view.

I still have to try it myself though.


If you don't have access to the source code then implementing it in a partial class should be ok I guess.

Feb 24, 2012 at 6:08 PM

That's cool. Thank you so much. On the way, I'll give it a try and udpate back.