C1MenuItem ContextMenu DarkMaterial Theme bad styling

Posted by: davide.galli on 13 June 2023, 9:35 pm EST

  • Posted 13 June 2023, 9:35 pm EST - Updated 13 June 2023, 9:40 pm EST

    Hello dears, I am trying to use the ContextMenu from any c1 component, but I am having a strange behaviour with the styling.

    The standard context menu is fine, but the custom one is badly styled.

    I am currently using this code:

    <c1:FlexGrid.ContextMenu>
                    <ContextMenu>
                        <c1:C1MenuItem Height="Auto"
                                       Width="Auto"
                                       Header="AddItem" />
                        <c1:C1MenuItem Height="Auto"
                                       Width="Auto"
                                       Header="RemoveItem" />
                    </ContextMenu>
                </c1:FlexGrid.ContextMenu>


    This is the result



    Since there is no documentation about this, how can I avoid the empty spaces before and after the proper menu?

    Seems like there are empty spaces for something, but no documentation is provided about this.

    If I use the system style, all is fine…

    Thank you and best regards

  • Posted 14 June 2023, 6:30 pm EST

    Hi Davide,

    The standard ContextMenu control does not support C1MenuItems. To achieve this functionality, you will need to use C1ContextMenu instead.

    Furthermore, it is not possible to directly add C1ContextMenu at the flexgrid level using XAML code. To accomplish this, you can add the following code in the code-behind file:

    grid.ShowSelectionMenu = false;
                grid.CellTapped += (s, e) =>
                {
                    if (e.Event.IsRightTapped)
                    {
                        var hitTest = grid.HitTest(e.Event.OriginalEventArgs);
                        if (hitTest.CellType == GridCellType.Cell)
                        {
                            var contextMenu = new C1ContextMenu();
                            contextMenu.Items.Add(new C1MenuItem
                            {
                                IconTemplate = null,
                                Header = "AddItem",
                            });
                            contextMenu.Items.Add(new C1MenuItem
                            {
                                IconTemplate = null,
                                Header = "RemoveItem",
                            });
                            contextMenu.Show(e.Event.OriginalEventArgs.OriginalSource as FrameworkElement);
                        }
                    }
                };

    We have attached a sample application for your reference. See ContentMenuItemSpaceFG.zip

    Kindly let us know if you need any further help regarding this.

    Thanks & Regards,

    Aastha

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels