I have set contextmenu for xamgrid like:
<XamGrid ItemsSource="{Binding MyList, Mode=TwoWay}"><ig:ContextMenuService.Manager> <ig:ContextMenuManager ModifierKeys="None" OpenMode="RightClick" > <ig:ContextMenuManager.ContextMenu> <ig:XamContextMenu Opening="XamContextMenu_Opening"> <ig:XamContextMenu.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <CheckBox Click="CheckBox_Click" Tag="{Binding ID}" IsChecked="{Binding IsChecked, Mode=TwoWay}" /> <TextBlock Text="{Binding MyName}" Margin="5,0,0,0"/> </StackPanel> </DataTemplate> </ig:XamContextMenu.ItemTemplate> </ig:XamContextMenu> </ig:ContextMenuManager.ContextMenu> </ig:ContextMenuManager></ig:ContextMenuService.Manager><ig:XamGrid.Columns>.....</ig:XamGrid.Columns></XamGrid>
there is a checkbox in side the contextmenu. then in Click event handler for this checkbox, I want to know the specific row of xamgrid when rightclick hit on it. How can I do it in code for checkbox Click event handler?
right now, I need to click the row firstly, then rightclick on the row for contextmenu, then I get the row from selected row. This is not user friendly. So I want to one right click for all.
Hello,
I am just cheking if you need any further assitance on this matter.
Hi,
My idea was to store a reference to the clicked row when opening the context menu, and then use that reference in Checkbox click event handler, e.g.:
private Row _row; private void XamContextMenu_Opening(object sender, OpeningEventArgs e) { _row = (from x in e.GetClickedElements<CellsPanel>() select x.Row).FirstOrDefault() as Row; // Discard displaying the context menu when not clicking on data rows: if (_row == null || _row.RowType != RowType.DataRow) { e.Cancel = true; } } private void CheckBox_Click(object sender, RoutedEventArgs e) { // Do something on the _row object here }
Hope this helps,
Hi, thank you very much. I already have above code in XamContextMenu_Opening event handler. My question is how to get the row in checkbox click event hander after right click on the row and contextmenu is popup.
You could store a reference to the clicked row when the context menu is being opened.
Your code should look something like this:
private void XamContextMenu_Opening(object sender, Infragistics.Controls.Menus.OpeningEventArgs e) { Row row = (from x in e.GetClickedElements<CellsPanel>() select x.Row).FirstOrDefault() as Row; // Discard displaying the context menu when not clicking on data rows: if (row == null || row.RowType != RowType.DataRow) { e.Cancel = true; } }