Hi.
In a Xamdatagrid I added a menuitem in HeaderLabelArea from the Code behind. This is code:
Dim MyMenuitem As New MenuItem MyMenuitem.Header = "Move to first" AddHandler MyMenuitem.Click, AddressOf Me.MenuItem_Click Dim MyContextMenu As New ContextMenu MyContextMenu.Items.Add(MyMenuitem) MyMenuitem.CommandParameter = MyContextMenu Dim MyStyleForHeaderLabel As New Style(GetType(HeaderLabelArea)) MyStyleForHeaderLabel.Setters.Add(New Setter(ContextMenuProperty, MyContextMenu)) MyXamdatagrid.FieldLayoutSettings.HeaderLabelAreaStyle = MyStyleForHeaderLabel
But now I can not intercept what column the menuitem has been opened so that I can do the operation
Can you help me.
Thank you so much
Ok
Thank you so much.
Hello Francesco,
You can add the ContextMenu to LabelPreseter instead of HeaderLabelArea. This way you will be able to use ContextMenu's PlacementTarget property, which returns the UIElement relative to which the menu is positioned when it was clicked, for example:
Dim MyMenuitem As New MenuItemMyMenuitem.Header = "Move to first" AddHandler MyMenuitem.Click, AddressOf Me.MenuItem_Click Dim MyContextMenu As New ContextMenuMyContextMenu.Items.Add(MyMenuitem) MyMenuitem.CommandParameter = MyContextMenuDim MyStyleForHeaderLabel As New Style(GetType(LabelPresenter))MyStyleForHeaderLabel.Setters.Add(New Setter(ContextMenuProperty, MyContextMenu))MyXamdatagrid.FieldSettings.LabelPresenterStyle= MyStyleForHeaderLabel
Private Sub MyMenuitem_Click(sender As Object, e As RoutedEventArgs) Dim lbl As LabelPresenter= TryCast(TryCast(e.OriginalSource, MenuItem).Parent, ContextMenu).PlacementTarget as LabelPresenterEnd Sub
Let me know if you have any questions.
Sincerely,ZhivkoAssociate Software Developer