GithubHelp home page GithubHelp logo

layoutchildaddedrepro's Introduction

LayoutChildAddedRepro

A .NET MAUI 6.0.100 reproduction sample for Layout.ChildAdded.

Bug Description

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");

Reproduction Steps

  1. Install .NET MAUI
  2. Download/Clone this repo: https://github.com/brminnick/LayoutChildAddedRepro
  3. In MainPage.xaml, confirm ChildAdded is subscribed to HandleChildAdded
  4. In MainPage.xaml.cs, confirm OnAppearing triggers the following DisplayAlert:
    await DisplayAlert("OnAppearing Fired", "Click OK to add a Green Box View", "OK");
  5. In MainPage.OnAppearing, confirm a green BoxView is added to the `Grid:
    var greenBox = new BoxView { BackgroundColor = Colors.Green };
    GridLayout.SetRow(greenBox, 1);
    GridLayout.SetColumn(greenBox, 0);
    
    MainGrid.Add(greenBox);
  6. Confirm HandleChildAdded triggers DisplayAlert:
    async void HandleChildAdded(object sender, ElementEventArgs e)
    {
      await DisplayAlert("Child Added", $"Added a {e.Element.GetType().FullName}", "OK");
    }
  7. In the terminal, navigate to the downloaded LayoutChildAddedRepro repo
  8. In the terminal, run LayoutChildAddedRepro.sln by 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
  9. In the simulator/device, confirm the DisplayAlert appears

image

  1. In the simulator, click OK
  2. In the simulator, confirm a Green Box is added to MainPage

image

  1. In the simulator, confirm the second DisplayAlert does not appear
  • If ChildAdded fires, a second DisplayAlert should appear, but ChildAdded does not fire

layoutchildaddedrepro's People

Contributors

brminnick avatar

Stargazers

RoyLai avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.