Let’s say i got this ContextMenu:
<Style x:Key="{x:Type ContextMenu}" TargetType="{x:Type ContextMenu}">
<Setter Property="VerticalOffset" Value="-10"/>
<Setter Property="HorizontalOffset" Value="-10"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContextMenu}">
<Border Background="Transparent">
<Border.Effect>
<DropShadowEffect BlurRadius="10" ShadowDepth="0" Opacity="0.5"/>
</Border.Effect>
<Border Margin="10" Style="{StaticResource MenuBorderStyle}">
<Grid x:Name="SubMenu" Grid.IsSharedSizeScope="True">
<!-- StackPanel holds children of the menu. This is set by IsItemsHost=True -->
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/>
</Grid>
</Border>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
So as you can see, i offset the appearance of the menu by 10 pixels to the top and to the left, getting the top-left corner of the ContextMenu to be right under the cursor.
In fact, because of Border‘s margin of 10 pixels, the whole control shoule be more left-top than a cursor, because the control it self starts with a shadow.
And, as you can have guessed, when the context menu appears not on the bottom-right side of the cursor (say the cursor is near bottom or left side of the screen), the offset needs to be changed to an opposite (by either either X or Y or both coordinates).
The question is how to do that by xaml?
(sorry for my english)
Try setting
Placementproperty toAbsolutePoint. Check this out as well, it might help you.