diff --git a/src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs index 69f267a605..b0dd30a878 100644 --- a/src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs +++ b/src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs @@ -87,9 +87,11 @@ namespace Avalonia.Automation.Peers foreach (var child in children) { - if (child is Control c && c.IsVisible) + if (child is Control c) { - result.Add(GetOrCreate(c)); + var peer = GetOrCreate(c); + if (c.IsVisible) + result.Add(peer); } } diff --git a/tests/Avalonia.Controls.UnitTests/Automation/ControlAutomationPeerTests.cs b/tests/Avalonia.Controls.UnitTests/Automation/ControlAutomationPeerTests.cs index c6aaa2205c..5cd47cf27b 100644 --- a/tests/Avalonia.Controls.UnitTests/Automation/ControlAutomationPeerTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Automation/ControlAutomationPeerTests.cs @@ -102,7 +102,7 @@ namespace Avalonia.Controls.UnitTests.Automation } [Fact] - public void Updates_Children_When_Visibility_Changes() + public void Updates_Children_When_Visibility_Changes_From_Visible_To_Invisible() { var panel = new Panel { @@ -126,6 +126,27 @@ namespace Avalonia.Controls.UnitTests.Automation children = target.GetChildren(); Assert.Equal(2, children.Count); } + + [Fact] + public void Updates_Children_When_Visibility_Changes_From_Invisible_To_Visible() + { + var panel = new Panel + { + Children = + { + new Border(), + new Border { IsVisible = false }, + }, + }; + + var target = CreatePeer(panel); + var children = target.GetChildren(); + Assert.Equal(1, children.Count); + + panel.Children[1].IsVisible = true; + children = target.GetChildren(); + Assert.Equal(2, children.Count); + } } public class Parent