A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

114 lines
3.7 KiB

using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.Media;
namespace ControlCatalog.Pages
{
public partial class TabbedPageWithDrawerPage : UserControl
{
public TabbedPageWithDrawerPage()
{
InitializeComponent();
Loaded += (_, _) => ShowSection("Home");
}
private void OnSectionSelected(object? sender, RoutedEventArgs e)
{
if (sender is Button btn && btn.Tag is string section)
{
ShowSection(section);
DemoDrawer.IsOpen = false;
}
}
private void ShowSection(string section)
{
SectionHost.Content = section switch
{
"Home" => CreateHomeTabbed(),
_ => CreatePlainPage(section)
};
}
private static Control CreatePlainPage(string section)
{
var (subtitle, icon) = section switch
{
"Explore" => ("Discover new content.", "📍"),
"Favorites" => ("Items you've saved.", "❤"),
_ => (string.Empty, string.Empty)
};
return new StackPanel
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Spacing = 8,
Children =
{
new TextBlock
{
Text = section,
FontSize = 22,
FontWeight = FontWeight.SemiBold,
HorizontalAlignment = HorizontalAlignment.Center
},
new TextBlock
{
Text = subtitle,
FontSize = 13,
Opacity = 0.7,
TextWrapping = TextWrapping.Wrap,
TextAlignment = TextAlignment.Center,
MaxWidth = 300
}
}
};
}
private static TabbedPage CreateHomeTabbed() => new()
{
TabPlacement = TabPlacement.Bottom,
Pages = new[]
{
new ContentPage
{
Header = "Featured",
Content = new TextBlock
{
Text = "Featured content",
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
FontSize = 18,
Opacity = 0.7
}
},
new ContentPage
{
Header = "Recent",
Content = new TextBlock
{
Text = "Recent activity",
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
FontSize = 18,
Opacity = 0.7
}
},
new ContentPage
{
Header = "Popular",
Content = new TextBlock
{
Text = "Popular right now",
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
FontSize = 18,
Opacity = 0.7
}
}
}
};
}
}