A .NET MAUI 6.0.100 reproduction sample for Layout.ChildAdded.
The Layout.ChildAdded event does not fire when an IView is added to a Layout like a Grid or a StackLayout.
protected override void OnAppearing()
{
base.OnAppearing();
var stackLayout = new StackLayout();
stackLayout.ChildAdded += HandleChildAdded
stackLayout.Children.Add(new BoxView()); // `ChildAdded` does not fire
}
// This Event Handler Does Not Execute because `ChildAdded` does not fire
async void HandleChildAdded(object sender, ElementEventArgs e) =>
await DisplayAlert("Child Added", $"Added a {e.Element.GetType().FullName}", "OK");- Install .NET MAUI
- Download/Clone this repo: https://github.com/brminnick/LayoutChildAddedRepro
- In
MainPage.xaml, confirmChildAddedis subscribed toHandleChildAdded - In
MainPage.xaml.cs, confirmOnAppearingtriggers the followingDisplayAlert:await DisplayAlert("OnAppearing Fired", "Click OK to add a Green Box View", "OK");
- In
MainPage.OnAppearing, confirm a greenBoxViewis added to the `Grid:var greenBox = new BoxView { BackgroundColor = Colors.Green }; GridLayout.SetRow(greenBox, 1); GridLayout.SetColumn(greenBox, 0); MainGrid.Add(greenBox);
- Confirm
HandleChildAddedtriggersDisplayAlert:async void HandleChildAdded(object sender, ElementEventArgs e) { await DisplayAlert("Child Added", $"Added a {e.Element.GetType().FullName}", "OK"); }
- In the terminal, navigate to the downloaded
LayoutChildAddedReprorepo - In the terminal, run
LayoutChildAddedRepro.slnby entering the following command for your specific simulator/device- iOS:
dotnet build -t:run -f:net6.0-ios - Android:
dotnet build -t:run -f:net6.0-android - MacCatalyst:
dotnet build -t:run -f:net6.0-maccatalyst
- iOS:
- In the simulator/device, confirm the
DisplayAlertappears
- In the simulator, click OK
- In the simulator, confirm a Green Box is added to
MainPage
- In the simulator, confirm the second
DisplayAlertdoes not appear
- If
ChildAddedfires, a secondDisplayAlertshould appear, butChildAddeddoes not fire

