Reputation: 1408
I'm trying to put my ContextMenu below my UserControl without success:
But the contextMenu is always appears near the mouse cursor and not under my Control.
Here is my code :
Main Page :
<pm:Bouton_Accueil x:Name="grid_manager" ContextMenuService.Placement="Bottom" Margin="0,0,0,0" Grid.Column="0">
</pm:Bouton_Accueil>
In my code :
ContextMenu sousMenuManager = new System.Windows.Controls.ContextMenu();
sousMenuManager.Style = (Style)FindResource("StyleContext");
sousMenuManager.Width = 133;
this.grid_manager.ContextMenu = sousMenuManager;
ContextMenuService.SetPlacement(this.grid_manager, System.Windows.Controls.Primitives.PlacementMode.Bottom);
public void MouseDown(object sender, RoutedEventArgs e)
{
sousMenuManager.IsOpen = true;
}
I have the same issue as this post : How can I tell a ContextMenu to place itself relatively to its control and not the cursor?
How can I just tell my ContextMenu to place itself below my Control ?
Thanks
Upvotes: 0
Views: 989
Reputation: 18580
Try this, instead ContextMenuService.Placement on button, Set Placement on contextmenu itself like
sousMenuManager.Placement = PlacementMode.Bottom;
and in mousedown handler set the placementtarget for the context menu to your grid_manager
sousMenuManager.PlacementTarget = grid_manager;
sousMenuManager.IsOpen = true;
Upvotes: 3