I put ContextMenu for each row in 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>
when user right click the row, ContextMenu popup, when click checked box inside the ContextMenu, the popup is still there. I need to click on somewhere outside of the ContextMenu popup, the popup will be gone.
So I want the ContextMenu popup gone when I click on checkbox inside the ContextMenu, how to implement it in code-behind for CheckBox_Click?
Hi,
If you need to close the ContextMenu in the CheckBox_Click method, you'll need to add an x:Name attribute to your grid, and then use code similar to this (assuming your grid is named 'igGrid'):
private void CheckBox_Click(object sender, RoutedEventArgs e){ ContextMenuService.GetManager(igGrid).ContextMenu.IsOpen = false;}
The other option is to use the built-in CheckBoxes functionality of the ContextMenu and its IsCheckable / IsChecked properties. Using this approach the context menu will be closed automatically when clicking the checkbox:
<ig:ContextMenuService.Manager> <ig:ContextMenuManager ModifierKeys="None" OpenMode="RightClick"> <ig:ContextMenuManager.ContextMenu> <ig:XamContextMenu Opening="XamContextMenu_Opening"> <ig:XamContextMenu.DefaultItemsContainer> <DataTemplate> <ig:XamMenuItem IsCheckable="True" IsChecked="{Binding IsChecked, Mode=TwoWay}" Header="{Binding MyName}" /> </DataTemplate> </ig:XamContextMenu.DefaultItemsContainer> </ig:XamContextMenu> </ig:ContextMenuManager.ContextMenu> </ig:ContextMenuManager> </ig:ContextMenuService.Manager>
Hope this helps,
Thank you. It' working.