Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Starward/Features/Gacha/GachaLogPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,11 @@

<ScrollViewer x:Name="ScrollViewer_GachaStats"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollMode="Auto">
ScrollViewer.HorizontalScrollMode="Auto"
PointerPressed="ScrollViewer_GachaStats_PointerPressed"
PointerMoved="ScrollViewer_GachaStats_PointerMoved"
PointerReleased="ScrollViewer_GachaStats_PointerReleased"
PointerExited="ScrollViewer_GachaStats_PointerExited">
<Grid x:Name="Grid_GachaStats"
Margin="20,0,20,16"
Background="Transparent">
Expand Down
60 changes: 60 additions & 0 deletions src/Starward/Features/Gacha/GachaLogPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Imaging;
using Microsoft.UI.Xaml.Navigation;
Expand All @@ -25,6 +26,7 @@
using System.Threading;
using System.Threading.Tasks;
using Vanara.PInvoke;
using Windows.Foundation;
using Windows.Storage;
using Windows.System;

Expand All @@ -44,6 +46,13 @@ public sealed partial class GachaLogPage : PageBase
private GachaLogService _gachaLogService;


private bool _isDragging;

private Point _dragStartPoint;

private double _dragStartHorizontalOffset;



public GachaLogPage()
{
Expand Down Expand Up @@ -197,6 +206,57 @@ private void Grid_GachaStats_PointerWheelChanged(object sender, Microsoft.UI.Xam



private void ScrollViewer_GachaStats_PointerPressed(object sender, PointerRoutedEventArgs e)
{
if (sender is not ScrollViewer scrollViewer) return;
// 仅响应左键按下
var pointerPoint = e.GetCurrentPoint(scrollViewer);
if (!pointerPoint.Properties.IsLeftButtonPressed) return;
_isDragging = true;
_dragStartPoint = pointerPoint.Position;
_dragStartHorizontalOffset = scrollViewer.HorizontalOffset;
scrollViewer.CapturePointer(e.Pointer);
}



private void ScrollViewer_GachaStats_PointerMoved(object sender, PointerRoutedEventArgs e)
{
if (!_isDragging || sender is not ScrollViewer scrollViewer) return;
var pointerPoint = e.GetCurrentPoint(scrollViewer);
if (!pointerPoint.Properties.IsLeftButtonPressed) return;
// 计算偏移
double deltaX = _dragStartPoint.X - pointerPoint.Position.X;
double targetOffset = _dragStartHorizontalOffset + deltaX;
// 限制滚动边界
targetOffset = Math.Max(0, Math.Min(targetOffset, scrollViewer.ScrollableWidth));
scrollViewer.ChangeView(targetOffset, null, null, true);
}



private void ScrollViewer_GachaStats_PointerReleased(object sender, PointerRoutedEventArgs e)
{
ResetDragState(sender as ScrollViewer, e);
}



private void ScrollViewer_GachaStats_PointerExited(object sender, PointerRoutedEventArgs e)
{
ResetDragState(sender as ScrollViewer, e);
}



private void ResetDragState(ScrollViewer? scrollViewer, PointerRoutedEventArgs e)
{
_isDragging = false;
scrollViewer?.ReleasePointerCapture(e.Pointer);
}



private async Task UpdateWikiDataAsync()
{
try
Expand Down
Loading