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

TextBox in AdornerLayer causes collection modified exception #14483

Closed
BAndysc opened this issue Feb 4, 2024 · 0 comments · Fixed by #14484
Closed

TextBox in AdornerLayer causes collection modified exception #14483

BAndysc opened this issue Feb 4, 2024 · 0 comments · Fixed by #14484
Labels

Comments

@BAndysc
Copy link
Contributor

BAndysc commented Feb 4, 2024

Describe the bug

When a TextBox with non empty Text is added to an AdornerLayer and no text box has ever been focused yet, the next Measure pass will run ApplyTemplate on the textbox, this will access the VisualLayerManager.TextSelectorLayer property, the getter will create the layer and Collection Was Modified while Enumeration exception will be thrown, because all those methods will be run from within VisualLayerManager's MeasureOverride, which iterates through its layers.

To Reproduce

Steps to reproduce the behavior:

        [Fact]
        public void TextBox_In_AdornerLayer_Will_Not_Cause_Collection_Modified_In_VisualLayerManager()
        {
            using (UnitTestApplication.Start(Services))
            {
                var button = new Button();
                var root = new TestRoot()
                {
                    Child = new VisualLayerManager()
                    {
                        Child = button
                    }
                };
                var adorner = new TextBox { Template = CreateTemplate(), Text = "a" };

                var adornerLayer = AdornerLayer.GetAdornerLayer(button);
                adornerLayer.Children.Add(adorner);
                AdornerLayer.SetAdornedElement(adorner, button);

                root.Measure(Size.Infinity);
            }
        }

Expected behavior

No crash

Environment

  • Avalonia-Version: 11.1.999-cibuild0044396-beta (latest master as of today)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant