Reputation: 811
I am developing a Windows Mobile 6.5.3 application. My question is how can I open the Menu popup programmatically.
What I did is I simulate the touch event. by using
[DllImport("coredll")] private static extern void mouse_event(MOUSEEVENTF dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
but here the problem is I need to specify the location of menu button and also it is showing some glance of mouse pointer, which I don't like...
Is there any message which I can send and the popup for the menu will open?
As requested I am adding some more information. I want to open the popup which opens after pressing the menu button programmatically.
Upvotes: 0
Views: 289
Reputation: 312
Get the context menu from the control then use the Show()
method of the context menu.
EDIT: answer modified and code changed
This is what I've done to have it work for me.
ContextMenu ctxMenu = BTN_TheButtonControlThatYouPressed.ContextMenu;
ctxMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
ctxMenu.IsOpen = true;
Now, because your context menu has been assigned to your form instead of your button you simply swap out the "BTN_TheButtonControl..." for a simple "this" which should "target" the form.
SO - add the following code to the button's click event and you should be okay.
ContextMenu ctxMenu = this.ContextMenu;
ctxMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
ctxMenu.IsOpen = true;
** not sure what's going on with the carriage returns... can't get 'em to go for just the second block of code...
Upvotes: 0