Skip to content

The SFML form embedded in Avalonia cannot receive any events #288

Open

Description

System: windows。
I used. net to create a win32 handle in Avalonia, then created a window using SFML and embedded it into the Avalonia form. The rendering and drawing are all normal, but the SFML form cannot receive any events. Is there anything that needs to be set?

Image

Image

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
          
            this.Loaded += MainWindow_Loaded;   
        }

        private void MainWindow_Loaded(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
        {
          
            var window = [new](http://www.google.com/search?q=new+msdn.microsoft.com) SFML.Graphics.RenderWindow(windowBox.Handle);
            // window.KeyPressed += Window_KeyPressed;
            window.MouseMoved += Window_MouseMoved; ;
             var circle = [new](http://www.google.com/search?q=new+msdn.microsoft.com) SFML.Graphics.CircleShape(100f)
            {
                FillColor = SFML.Graphics.Color.Blue,
                Position=[new](http://www.google.com/search?q=new+msdn.microsoft.com) Vector2f(500,500)
            };
            window.Draw(circle);

            // Finally, display the rendered frame on screen
            window.Display();
       
        }

        private void Window_MouseMoved(object? sender, SFML.Window.MouseMoveEventArgs e)
        {
           //Can In it
        }
    }
    public class NativeEmbeddingControl : NativeControlHost
    {
        public IntPtr Handle { get; private set; }

        protected override IPlatformHandle CreateNativeControlCore(IPlatformHandle parent)
        {

            var handle = base.CreateNativeControlCore(parent);
            Handle = handle.Handle;
            Console.WriteLine($"Handle : {Handle}");
            return handle;
        }
    }

Activity

  1. transferred this issue fromSFML/CSFMLon Mar 5, 2025
  2. eXpl0it3r commented on Mar 5, 2025

    @eXpl0it3r
    Member

    Moved the issue from CSFML to SFML.Net.

    Also there's a cross post on the forum, just in case someone posts an answer there: https://en.sfml-dev.org/forums/index.php?topic=29833.0

  3. AlaskanDruid commented on Jun 30, 2025

    @AlaskanDruid

    Where is the window.DispatchEvents() call?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions