2026-03-15 03:37:50 +08:00
|
|
|
|
using System;
|
2026-04-07 23:56:17 +08:00
|
|
|
|
using System.Linq;
|
2026-03-15 03:37:50 +08:00
|
|
|
|
using Avalonia.Controls;
|
2026-04-07 23:56:17 +08:00
|
|
|
|
using Avalonia.Input.GestureRecognizers;
|
2026-03-15 03:37:50 +08:00
|
|
|
|
using Avalonia.Interactivity;
|
|
|
|
|
|
using Avalonia.Layout;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Semi.Avalonia.Demo.Pages;
|
|
|
|
|
|
|
|
|
|
|
|
public partial class DrawerPageDemo : UserControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public DrawerPageDemo()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2026-04-07 23:56:17 +08:00
|
|
|
|
EnableMouseSwipeGesture(DemoDrawer);
|
2026-03-15 03:37:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnLoaded(RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnLoaded(e);
|
|
|
|
|
|
DemoDrawer.Opened += OnDrawerStatusChanged;
|
|
|
|
|
|
DemoDrawer.Closed += OnDrawerStatusChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnUnloaded(RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnUnloaded(e);
|
|
|
|
|
|
DemoDrawer.Opened -= OnDrawerStatusChanged;
|
|
|
|
|
|
DemoDrawer.Closed -= OnDrawerStatusChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnDrawerStatusChanged(object? sender, EventArgs e) => UpdateStatus();
|
|
|
|
|
|
|
|
|
|
|
|
private void OnToggleDrawer(object? sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
DemoDrawer.IsOpen = !DemoDrawer.IsOpen;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnGestureChanged(object? sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
DemoDrawer.IsGestureEnabled = GestureCheck.IsChecked == true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnMenuSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (DrawerMenu.SelectedItem is ListBoxItem item)
|
|
|
|
|
|
{
|
|
|
|
|
|
DemoDrawer.Content = new ContentPage
|
|
|
|
|
|
{
|
|
|
|
|
|
Header = item.Content?.ToString(),
|
|
|
|
|
|
Content = new TextBlock
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = $"{item.Content} page content",
|
|
|
|
|
|
FontSize = 16,
|
|
|
|
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
|
|
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
|
|
|
|
},
|
|
|
|
|
|
HorizontalContentAlignment = HorizontalAlignment.Stretch,
|
|
|
|
|
|
VerticalContentAlignment = VerticalAlignment.Stretch
|
|
|
|
|
|
};
|
|
|
|
|
|
DemoDrawer.IsOpen = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void UpdateStatus()
|
|
|
|
|
|
{
|
|
|
|
|
|
StatusText.Text = $"Drawer: {(DemoDrawer.IsOpen ? "Open" : "Closed")}";
|
|
|
|
|
|
}
|
2026-04-07 23:56:17 +08:00
|
|
|
|
|
|
|
|
|
|
private static void EnableMouseSwipeGesture(Control control)
|
|
|
|
|
|
{
|
|
|
|
|
|
var recognizer = control.GestureRecognizers
|
|
|
|
|
|
.OfType<SwipeGestureRecognizer>()
|
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
|
|
recognizer?.IsMouseEnabled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnLayoutChanged(object? sender, SelectionChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
DemoDrawer.DrawerLayoutBehavior = (sender as ComboBox)?.SelectedIndex switch
|
|
|
|
|
|
{
|
|
|
|
|
|
0 => DrawerLayoutBehavior.CompactOverlay,
|
|
|
|
|
|
1 => DrawerLayoutBehavior.CompactInline,
|
|
|
|
|
|
2 => DrawerLayoutBehavior.Split,
|
|
|
|
|
|
3 => DrawerLayoutBehavior.Overlay,
|
|
|
|
|
|
_ => DrawerLayoutBehavior.CompactOverlay
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2026-03-15 03:37:50 +08:00
|
|
|
|
}
|