livia-test/Livia/Views/Controls/PagingControl.xaml.cs
2025-03-28 14:31:53 +08:00

51 lines
1.4 KiB
C#

using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Input;
using Livia.ViewModels;
namespace Livia.Views.Controls;
/// <summary>
/// Interaction logic for PagingControl.xaml
/// </summary>
public partial class PagingControl
{
public PagingControl()
{
InitializeComponent();
}
private async void FirstButtonClick(object sender, RoutedEventArgs e)
{
await ((PagingControlViewModel)DataContext).First();
}
private async void PreviousButtonClick(object sender, RoutedEventArgs e)
{
await ((PagingControlViewModel)DataContext).Previous();
}
private async void NextButtonClick(object sender, RoutedEventArgs e)
{
await ((PagingControlViewModel)DataContext).Next();
}
private async void LastButtonClick(object sender, RoutedEventArgs e)
{
await ((PagingControlViewModel)DataContext).Last();
}
private async void PageBoxKeyDown(object sender, KeyEventArgs e)
{
if (e.Key != Key.Return)
return;
CurrentPageTextBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
await((PagingControlViewModel)DataContext).Refresh();
}
private void PageBoxOnPreview(object sender, TextCompositionEventArgs e)
{
Regex regex = new("[^0-9]+");
e.Handled = regex.IsMatch(e.Text);
}
}