I try to add child to flexlayout with a button's clicked event but noting happened. :S But when I remove a child from flexlayout it is removed. Would anyone help me please?
Can you show some code?
yeah sure. in this example first 12 item is added the page but after I clicked button 13. child is dont be add to flexlayout's childs.
but if I change code like this(for just trying) It can show 13 item on screen.
[XamlCompilation(XamlCompilationOptions.Compile)] public partial class Page1 : ContentPage { public Page1() { InitializeComponent(); } List<Grid> grids = new List<Grid> { new Grid{BackgroundColor=Color.Pink}, new Grid{BackgroundColor=Color.Red}, new Grid{BackgroundColor=Color.Accent}, new Grid{BackgroundColor=Color.Blue}, new Grid{BackgroundColor=Color.Purple}, new Grid{BackgroundColor=Color.DarkGoldenrod}, new Grid{BackgroundColor=Color.Green}, new Grid{BackgroundColor=Color.Khaki}, new Grid{BackgroundColor=Color.Gold}, new Grid{BackgroundColor=Color.Silver}, new Grid{BackgroundColor=Color.RosyBrown}, new Grid{BackgroundColor=Color.Tomato}, }; protected override void OnAppearing() { base.OnAppearing(); Method(); } private void Method() { if (layout.Children.Count > 0) layout.Children.Clear(); foreach (var item in grids) { item.Margin = 3; item.HeightRequest = (_global.ScreenWidth - ((3 * (item.Margin.Left + item.Margin.Right)) + (layout.Margin.Left + layout.Margin.Right))) / 3d; item.WidthRequest = (_global.ScreenWidth - ((3 * (item.Margin.Left + item.Margin.Right)) + (layout.Margin.Left + layout.Margin.Right))) / 3d; layout.Children.Add(item); } } private void Button_Clicked(object sender, EventArgs e) { grids.Add(new Grid { BackgroundColor = Color.Orange }); Method(); } }
}
Answers
Can you show some code?
yeah sure. in this example first 12 item is added the page but after I clicked button 13. child is dont be add to flexlayout's childs.
but if I change code like this(for just trying) It can show 13 item on screen.
}