picoe / Eto

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

[BUG] DocumentPage content loses focus if property changed #2606

Open marcoburato opened 6 months ago

marcoburato commented 6 months ago

Expected Behavior

Changing DocumentPage.Text on the active page causes its content to lose focus.

Actual Behavior

Changing DocumentPage.Text should not alter the focused component.

Steps to Reproduce the Problem

In the supplied code:

  1. Click on the textbox to focus it
  2. Start typing
  3. Observe how the TextBox.TextChanged handler adds a * to DocumentPage.Text and now the textbox is no longer focused.

I believe this happens because ThemedDocumentControlHandler.SetPageContent() always sets Content to null before setting it to something else.

In my actual code I'm using a custom Drawable and I noticed that OnLostFocus() does not get called, but OnUnLoad() is.

Code that Demonstrates the Problem

using System;
using Eto.Drawing;
using Eto.Forms;

namespace DocumentControlTest
{
    public class MainForm : Form
    {
        private DocumentPage _page;

        public MainForm()
        {
            Title = "My Eto Form";
            MinimumSize = new Size(400, 400);

            var textBox = new TextBox();
            textBox.TextChanged += TextBox_TextChanged;

            var page = new DocumentPage
            {
                Text = "Tab1",
                Content = new StackLayout
                {
                    Items =
                    {
                        textBox
                    }
                }
            };

            var documentControl = new DocumentControl();
            documentControl.Pages.Add(page);
            Content = documentControl;

            _page = page;
        }

        private void TextBox_TextChanged(object sender, EventArgs e)
        {
            _page.Text += "*";
        }
    }
}

Specifications