@@ -237,5 +237,79 @@ public async Task ShadowDoesNotLeak()
237237
238238 Assert . False ( reference . IsAlive , "VisualElement should not be alive!" ) ;
239239 }
240+
241+ [ Fact ]
242+ public void ShouldPropagateVisibilityToChildren ( )
243+ {
244+ var grid = new Grid ( ) { IsVisible = false } ;
245+ var label = new Label ( ) { IsVisible = true } ;
246+ grid . Add ( label ) ;
247+
248+ Assert . False ( label . IsVisible ) ;
249+ Assert . Equal ( grid . IsVisible , label . IsVisible ) ;
250+ }
251+
252+ [ Theory ]
253+ [ InlineData ( false , true , true , false , false , false ) ]
254+ [ InlineData ( true , false , true , true , false , false ) ]
255+ public void IsVisiblePropagates ( bool rootIsVisible , bool nestedIsVisible , bool childIsVisible , bool expectedRootVisibility , bool expectedNestedVisibility , bool expectedChildVisibility )
256+ {
257+ var root = new Grid ( ) { IsVisible = rootIsVisible } ;
258+ var nested = new Grid ( ) { IsVisible = nestedIsVisible } ;
259+ var child = new Button ( ) { IsVisible = childIsVisible } ;
260+
261+ nested . Add ( child ) ;
262+ root . Add ( nested ) ;
263+
264+ Assert . Equal ( root . IsVisible , expectedRootVisibility ) ;
265+ Assert . Equal ( nested . IsVisible , expectedNestedVisibility ) ;
266+ Assert . Equal ( child . IsVisible , expectedChildVisibility ) ;
267+ }
268+
269+ [ Fact ]
270+ public void IsVisibleParentCorrectlyUnsetsPropagatedChange ( )
271+ {
272+ var button = new Button ( ) ;
273+ var grid = new Grid { button } ;
274+
275+ grid . IsVisible = false ;
276+ Assert . False ( button . IsVisible ) ;
277+
278+ grid . IsVisible = true ;
279+ Assert . True ( button . IsVisible ) ;
280+ }
281+
282+ [ Fact ]
283+ public void ButtonShouldStayHiddenIfExplicitlySet ( )
284+ {
285+ var button = new Button { IsVisible = false } ;
286+ var grid = new Grid { button } ;
287+
288+ grid . IsVisible = false ;
289+ Assert . False ( button . IsVisible ) ;
290+
291+ // button stays hidden if it was explicitly set
292+ grid . IsVisible = true ;
293+ Assert . False ( button . IsVisible ) ;
294+ }
295+
296+ [ Fact ]
297+ public void ButtonShouldBeVisibleWhenExplicitlySetWhenParentIsVisible ( )
298+ {
299+ var button = new Button { IsVisible = false } ;
300+ var grid = new Grid { button } ;
301+
302+ // everything is hidden
303+ grid . IsVisible = false ;
304+ Assert . False ( button . IsVisible ) ;
305+
306+ // make buttin visible, but it should not appear
307+ button . IsVisible = true ;
308+ Assert . False ( button . IsVisible ) ;
309+
310+ // button appears when parent appears
311+ grid . IsVisible = true ;
312+ Assert . True ( button . IsVisible ) ;
313+ }
240314 }
241315}
0 commit comments