ConnectedAnimationDemoPage.xaml.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using System.Collections.Generic;
  3. using Avalonia.Controls;
  4. using Avalonia.Interactivity;
  5. using Avalonia.Layout;
  6. using Avalonia.Media;
  7. namespace ControlCatalog.Pages
  8. {
  9. public partial class ConnectedAnimationDemoPage : ContentPage
  10. {
  11. private static readonly (string Group, string Title, string Description, Func<UserControl> Factory)[] Demos = [];
  12. public ConnectedAnimationDemoPage()
  13. {
  14. InitializeComponent();
  15. Loaded += OnLoaded;
  16. }
  17. private async void OnLoaded(object? sender, RoutedEventArgs e)
  18. {
  19. await SampleNav.PushAsync(CreateHomePage(), null);
  20. }
  21. private ContentPage CreateHomePage()
  22. {
  23. var stack = new StackPanel
  24. {
  25. Margin = new Avalonia.Thickness(12),
  26. Spacing = 16
  27. };
  28. var groups = new Dictionary<string, WrapPanel>();
  29. var groupOrder = new List<string>();
  30. foreach (var (group, title, description, factory) in Demos)
  31. {
  32. if (!groups.ContainsKey(group))
  33. {
  34. groups[group] = new WrapPanel
  35. {
  36. Orientation = Orientation.Horizontal,
  37. HorizontalAlignment = HorizontalAlignment.Left
  38. };
  39. groupOrder.Add(group);
  40. }
  41. var demoFactory = factory;
  42. var demoTitle = title;
  43. var card = new Button
  44. {
  45. Width = 200,
  46. MinHeight = 80,
  47. Margin = new Avalonia.Thickness(0, 0, 8, 8),
  48. VerticalAlignment = VerticalAlignment.Top,
  49. HorizontalContentAlignment = HorizontalAlignment.Left,
  50. VerticalContentAlignment = VerticalAlignment.Top,
  51. Padding = new Avalonia.Thickness(12, 8),
  52. Content = new StackPanel
  53. {
  54. Spacing = 4,
  55. Children =
  56. {
  57. new TextBlock
  58. {
  59. Text = title,
  60. FontSize = 13,
  61. FontWeight = FontWeight.SemiBold,
  62. TextWrapping = TextWrapping.Wrap
  63. },
  64. new TextBlock
  65. {
  66. Text = description,
  67. FontSize = 11,
  68. Opacity = 0.6,
  69. TextWrapping = TextWrapping.Wrap
  70. }
  71. }
  72. }
  73. };
  74. card.Click += async (s, ev) =>
  75. {
  76. var headerGrid = new Grid { ColumnDefinitions = new ColumnDefinitions("*, Auto") };
  77. headerGrid.Children.Add(new TextBlock
  78. {
  79. Text = demoTitle,
  80. VerticalAlignment = VerticalAlignment.Center
  81. });
  82. var closeBtn = new Button
  83. {
  84. Content = new PathIcon
  85. {
  86. Data = Geometry.Parse("M4.397 4.397a1 1 0 0 1 1.414 0L12 10.585l6.19-6.188a1 1 0 0 1 1.414 1.414L13.413 12l6.19 6.189a1 1 0 0 1-1.414 1.414L12 13.413l-6.189 6.19a1 1 0 0 1-1.414-1.414L10.585 12 4.397 5.811a1 1 0 0 1 0-1.414z")
  87. },
  88. Background = Brushes.Transparent,
  89. BorderThickness = new Avalonia.Thickness(0),
  90. Padding = new Avalonia.Thickness(8, 4),
  91. VerticalAlignment = VerticalAlignment.Center
  92. };
  93. Grid.SetColumn(closeBtn, 1);
  94. headerGrid.Children.Add(closeBtn);
  95. closeBtn.Click += async (_, _) => await SampleNav.PopAsync(null);
  96. var page = new ContentPage
  97. {
  98. Header = headerGrid,
  99. Content = demoFactory(),
  100. HorizontalContentAlignment = HorizontalAlignment.Stretch,
  101. VerticalContentAlignment = VerticalAlignment.Stretch
  102. };
  103. NavigationPage.SetHasBackButton(page, false);
  104. await SampleNav.PushAsync(page, null);
  105. };
  106. groups[group].Children.Add(card);
  107. }
  108. foreach (var groupName in groupOrder)
  109. {
  110. stack.Children.Add(new TextBlock
  111. {
  112. Text = groupName,
  113. FontSize = 13,
  114. FontWeight = FontWeight.SemiBold,
  115. Margin = new Avalonia.Thickness(0, 0, 0, 4),
  116. Opacity = 0.6
  117. });
  118. stack.Children.Add(groups[groupName]);
  119. }
  120. var homePage = new ContentPage
  121. {
  122. Content = new ScrollViewer { Content = stack },
  123. HorizontalContentAlignment = HorizontalAlignment.Stretch,
  124. VerticalContentAlignment = VerticalAlignment.Stretch
  125. };
  126. NavigationPage.SetHasNavigationBar(homePage, false);
  127. return homePage;
  128. }
  129. }
  130. }