Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPF - ContextMenu's position doesn't work if grid size is changed by a grid splitter. #3908

Closed
Dragmoria opened this issue Nov 26, 2021 · 4 comments
Milestone

Comments

@Dragmoria
Copy link

Bug Report

  • What version of the product are you using?

    • Version CefSharp.wpf 95.7.141, I'm running the MinimalExample.wpf project.
  • What architecture x86 or x64?
    Problem occurs on bot x86 and x64

  • What version of .Net?
    Problem occurs in MinimalExample.wpf which seems to use .NET 4.5.2. The issue also occurs when I run my own project which is .NET 5.0

  • On what operating system?
    Windows 10 Pro

  • Are you using WinForms, WPF or OffScreen?
    WPF

  • What steps will reproduce the problem?
    I wanted to add a panel to the left of the browser with a treeview and this panel had to be resizable. When I did so i noticed that whenever I right clicked on the browser the context menu shows at the position of the click. But once I resize the grid with a gridsplitter and right click on the browser the context menu does not show at the position of the click.

    To see if this was an issue with my own project I tried adding a gridsplitter to the MinimalExample.WPF project and the same occured here. I have tried to implement Run Cef.DoMessageLoopWork manually in WPF app from amaitland to see if this may help but it didn't affect this issue.

    To reproduce this issue I added a simple gridsplitter to the already existing MainWindow.xaml in the MinimalExample.WPF project.

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
    
        <Grid Grid.Column="0">
            
        </Grid>
    
        <GridSplitter Grid.Column="0" Width="4"  />
    
        <Grid Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid>
                ...
                <!-- CefBrowser sits somewhere here -->
                ...
            </Grid>    
        </Grid>
    </Grid>
    
  • What is the expected output? What do you see instead?
    The expected behaviour would be that the context menu would show at the position of the mouseclick but this is not the case. The following two images show the actual output.

    Without Resize:
    image

    With resize:
    image

    In both cases I clicked on the center of the G. Without a resize it works well but after a resize the position doesn't match.

  • Please provide any additional information below.
    I have none.

  • Does this problem also occur in the CEF Sample Application
    If MinimalExample.WPF is also a Sample Application then yes. I'm unable to run any of the examples from https://github.com/cefsharp/CefSharp.

@amaitland amaitland changed the title ContextMenu's position doesn't work if grid size is changed by a grid splitter. WPF - ContextMenu's position doesn't work if grid size is changed by a grid splitter. Nov 26, 2021
@amaitland
Copy link
Member

Please test with the 96-pre release. See #3902 (comment)

A custom WPF specific context menu is now used instead of the default CEF native menu (#1767)

@Dragmoria
Copy link
Author

Dragmoria commented Nov 26, 2021

I just tried this in my own project and if I remove the web browser menu handler it works now which is awesome, if I don't do that it still does goes to the wrong position. I do wonder how I would go about adding extra items or removing certain items from the context menu if that is at all possible still since using this with a menu handler doesn't work?

@amaitland
Copy link
Member

I do wonder how I would go about adding extra items or removing certain items from the context menu if that is at all possible still since using this with a menu handler doesn't work?

You can extend the WPF implementation, see https://github.com/cefsharp/CefSharp/blob/cefsharp/96/CefSharp.Wpf.Example/Handlers/MenuHandler.cs for example of adding a new command, you can customise the existing model as you would normally.

@Dragmoria
Copy link
Author

Awesome that all works. Ty very much.

@amaitland amaitland added this to the 96.0.x milestone Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants