using System.Threading.Tasks; using Avalonia; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Media; namespace ControlCatalog.Pages; public partial class ModernAppPage : UserControl { // Palette static readonly Color Primary = Color.Parse("#0dccf2"); static readonly Color BgLight = Color.Parse("#f5f8f8"); static IBrush BgBrush => new SolidColorBrush(BgLight); DrawerPage? _drawerPage; NavigationPage? _navPage; ScrollViewer? _infoPanel; TextBlock? _pageTitle; Button? _selectedNavBtn; public ModernAppPage() { InitializeComponent(); _infoPanel = this.FindControl("InfoPanel"); _drawerPage = this.FindControl("DrawerPageControl"); _navPage = this.FindControl("NavPage"); _pageTitle = this.FindControl("PageTitle"); if (_navPage != null) NavigateToDiscover(); } protected override void OnLoaded(RoutedEventArgs e) { base.OnLoaded(e); UpdateInfoPanelVisibility(); } protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) { base.OnPropertyChanged(change); if (change.Property == BoundsProperty) UpdateInfoPanelVisibility(); } void UpdateInfoPanelVisibility() { if (_infoPanel != null) _infoPanel.IsVisible = Bounds.Width >= 640; } void OnNavClick(object? sender, RoutedEventArgs e) { if (sender is not Button btn) return; SelectNavButton(btn); _drawerPage!.IsOpen = false; switch (btn.Tag?.ToString()) { case "Discover": NavigateToDiscover(); break; case "MyTrips": NavigateToMyTrips(); break; case "Profile": NavigateToProfile(); break; case "Settings": NavigateToSettings(); break; } } void OnCloseDrawer(object? sender, RoutedEventArgs e) { if (_drawerPage != null) _drawerPage.IsOpen = false; } void SelectNavButton(Button btn) { if (_selectedNavBtn != null) _selectedNavBtn.Background = Brushes.Transparent; _selectedNavBtn = btn; btn.Background = new SolidColorBrush(Color.Parse("#1A0dccf2")); } async Task Navigate(ContentPage page) { if (_navPage == null) return; NavigationPage.SetHasBackButton(page, false); NavigationPage.SetHasNavigationBar(page, false); await _navPage.PopToRootAsync(); await _navPage.PushAsync(page); } async void NavigateToDiscover() { if (_pageTitle != null) _pageTitle.Text = "Discover"; SelectNavButton(this.FindControl