GridRow.cs 739 B

123456789101112131415161718192021222324
  1. using System.Collections.Specialized;
  2. using Avalonia.Controls;
  3. using Avalonia.Layout;
  4. namespace TextTestApp
  5. {
  6. public class GridRow : Grid
  7. {
  8. protected override void ChildrenChanged(object? sender, NotifyCollectionChangedEventArgs e)
  9. {
  10. base.ChildrenChanged(sender, e);
  11. while (Children.Count > ColumnDefinitions.Count)
  12. ColumnDefinitions.Add(new ColumnDefinition { SharedSizeGroup = "c" + ColumnDefinitions.Count });
  13. for (int i = 0; i < Children.Count; i++)
  14. {
  15. SetColumn(Children[i], i);
  16. if (Children[i] is Layoutable l)
  17. l.VerticalAlignment = VerticalAlignment.Center;
  18. }
  19. }
  20. }
  21. }