picoe / Eto

Cross platform GUI framework for desktop and mobile applications in .NET
Other
3.56k stars 325 forks source link

[WPF/WinForms] Event handling in child and parent controls #542

Open SlowLogicBoy opened 8 years ago

SlowLogicBoy commented 8 years ago

When I mark event as handled in child control it is still firing up in parent control Example Code (DoubleClick GridView):

    public class MainForm : Form
    {
        public MainForm()
        {
            var grid = new GridView
            {
                Columns = { new GridColumn {HeaderText = "Column"} }
            };
            grid.MouseDoubleClick += (sender, args) =>
            {
                //Do some stuff.
                args.Handled = true;
            };

            var tab = new TabControl
            {
                Pages =
                {
                    new TabPage
                    {
                        Text = "TabPage",
                        Content = grid
                    }
                }
            };

            tab.MouseDoubleClick += (sender, args) =>
            {
                MessageBox.Show(this, "This should not be popping up when double clicking grid");
            };
            Content = tab;
            Size = new Size(600, 400);
        }
    } 

In WinForms event isn't firing in Parent controls at all (it doesn't care about Handled state). There should be some notes or something about how events should work in Eto, because in different platforms, events are handled differently and it's really hard to handle them. In API: MouseDoubleClick - Occurs when a mouse button is double clicked within the bounds of the control, so logically WinForms events are firing incorrectly.

cwensley commented 8 years ago

Thanks for reporting the issue! The way it is "supposed" to work is as you expect, where if you mark it as handled it shouldn't be bubbled up the parent hierarchy. Some controls handle the events intrinsically so the events won't bubble regardless of what you do (e.g. TextBox, Button, etc)

There is special code in Eto's WinForms platform to handle bubbling of events (as it by default does not do this at all). The TabControl probably needs some tweaks to get this to work correctly as it may be passing the events to the TabPage, but needs investigation.

As for why WPF does pass the event even when set as Handled is probably again related to the TabControl or GridView specifically as other controls have been tested with bubbling.

SlowLogicBoy commented 8 years ago

Thank you for your response. Since you cleared how events should work, I'll try to solve this issue myself however no promises :)