Git Product home page Git Product logo

Comments (4)

thevortexcloud avatar thevortexcloud commented on July 22, 2024

I have seen this before, not sure what causes it though. Interestingly, it works fine if you just shove everything into the Winform interop control and use a winform window. Although you do have to deal with winforms swallowing certain keypresses by default instead of passing them to the Avalonia control. Obviously using a winform window when trying to move away from winforms is not ideal.

from avalonia.

pauldumais avatar pauldumais commented on July 22, 2024

I'm digging into the issue in the Avalonia source code, it looks like WM_KEYDOWN events are being fired but not WM_CHAR events, this issue appears to be very similar to the behaviour of this issue:
#785

The resolution for that issue was to give focus to the window after it was shown, so it may be a similar situation with the new avalonia child window not receiving proper focus when being opened from a winforms app.

from avalonia.

pauldumais avatar pauldumais commented on July 22, 2024

Digging down further, it appears the issue is with the WinForms message loop, when running inside a WinForms application the message loop is handled by the WinForms Application class, while when running inside an Avalonia window it uses it's own Win32DispatcherImpl properly routing events. The WinForms Application message loop is looking for the Control.FromChildHandle() of the Window and it is not finding the Control to route the WM_CHAR event to. When running inside an Avalonia Interop hosting control all works fine as it finds the parent Form window from Control.FromChildHandle().

from avalonia.

pauldumais avatar pauldumais commented on July 22, 2024

I think I found a solution, it looks like the event loop was not started properly for the Avalonia window because it was launched from a WinForms app context relying on the WinForms event loop which was looking for a top level Windows.Form.Control to dispatch the WM_CHAR events to. The solution was to force the Avalonia Event loop to start with the new Window, so instead of Window.Show() I would call this method, this causes the Window to be displayed but also for the Avalonia Event loop to start:

Application.Current.Run(avaloniaWindow);

from avalonia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.