I'm using a xamDataGrid 10.3. I've implemented a context menu for a DataRecordPresenter using the following XAML
<igDP:XamDataGrid.Resources> <Style TargetType="{x:Type igDP:DataRecordPresenter}"> <EventSetter Event="ContextMenuOpening" Handler="DRPContextMenu"/> </Style> </igDP:XamDataGrid.Resources>
and the appropriate event handler
void DRPContextMenu(object sender, ContextMenuEventArgs e) { DataRecordPresenter dp = sender as DataRecordPresenter; ContextMenu c = new ContextMenu(); MenuItem itemFD = new MenuItem() { Header = "Layout: " + dp.Record.FieldLayout.ToString() }; c.Items.Add(itemFD); MenuItem itemInfo = new MenuItem() { Header = "Record Index: " + dp.Record.Index }; c.Items.Add(itemInfo); dp.ContextMenu = c; }
The context menu is not displayed reliably, but quite often just a little square is displayed on the grid (see attached screen shot).
Any idea what this could be? How can I get rid of this little square and make context menus more reliable?
Markus
Hi Matt
That was the solution! Since I added IsOpen = true, the context menu works properly.
Thank you very much!
Hi Markus,
In your DR:ContextMenu Event Handler, put the following line of code at the end.
c.IsOpen = true;
Sincerely, Matt Developer Support Engineer
Thanks for you suggestion. After changing the XAML code, the small rectangles do no longer appear. But part of the problem still exists: The context menus don't pop up reliably. I guess that it only pops up in 2/3 of the cases. In many cases the user needs to right click twice to bring up the context menu, which is quite annoying.
So it seems that rectangle is gone, but the underlying problem still persists.
Best Regards
HI,
I made the following changes to your Xaml, the small rectangle no longer appears.
<UserControl.Resources> <Style x:Key="LayoutIdx1Style" TargetType="{x:Type igDP:DataRecordCellArea}"> <Setter Property="Background" Value="Silver"/> <Setter Property="ContextMenu"> <Setter.Value> <ContextMenu AllowDrop="False"/> </Setter.Value> </Setter> </Style> </UserControl.Resources> <Grid> <!--<Grid.ContextMenu> <ContextMenu AllowDrop="False" /> </Grid.ContextMenu>-->
Hi Yanko
Thank you for looking into the code. Unfortunately I don't see your point. The ContextMenu resp. the style that is used for the context menu is part of the XAML declaration of the xamDataGrid named xamMainDataGrid.
In the event handler for context menues I then connect the context menu to a DataRecordPresenter (see event handler DRPContextMenu).
So please could you explain again, why you think that the context menu is for the grid and not the XamDataGrid? What advantage has the xamContextMenu compared to the ContextMenu (by the way I implemented this according to a forum message).