using XFEEDToolBox.ViewModels;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
namespace XFEEDToolBox.Views;
public sealed partial class UpgradeListContent : UserControl
{
public ToolboxViewModel ViewModel=>App.ViewModel;
public event Action? ExpandRequested,PinRequested,CloseRequested,DetailsRequested,DragStarted,DragUpdated,DragCompleted;
private bool floating,dragHovered;
private Pointer? draggingPointer;
private readonly SolidColorBrush dragNormal=new(Windows.UI.Color.FromArgb(8,255,255,255));
private readonly SolidColorBrush dragHover=new(Windows.UI.Color.FromArgb(20,255,255,255));
private readonly SolidColorBrush dragActive=new(Windows.UI.Color.FromArgb(34,255,255,255));
private readonly SolidColorBrush gripNormal=new(Windows.UI.Color.FromArgb(153,187,197,208));
private readonly SolidColorBrush gripHover=new(Windows.UI.Color.FromArgb(230,222,231,240));
private readonly SolidColorBrush gripActive=new(Windows.UI.Color.FromArgb(255,255,174,72));
public UpgradeListContent(){InitializeComponent();Unloaded+=(_,_)=>StopDragging();}
public void ConfigureFloating()
{
floating=true;ExpandListButton.Visibility=Visibility.Collapsed;
PinListButton.Visibility=CloseListButton.Visibility=DragHandle.Visibility=Visibility.Visible;
UpgradePreviewScroller.MaxHeight=double.PositiveInfinity;ToolTipService.SetToolTip(DragHandle,"按住拖动,松开停止");
}
public void ShowPinned(bool pinned)
{
PinListButton.Background=pinned?new SolidColorBrush(Windows.UI.Color.FromArgb(255,84,51,26)):new SolidColorBrush(Windows.UI.Color.FromArgb(0,0,0,0));
ToolTipService.SetToolTip(PinListButton,pinned?"取消置顶":"置顶");
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(PinListButton,pinned?"取消清单置顶":"置顶悬浮清单");
}
private void DragPressed(object sender,PointerRoutedEventArgs args)
{
if(!floating||draggingPointer is not null||!args.GetCurrentPoint(DragHandle).Properties.IsLeftButtonPressed)return;
if(!DragHandle.CapturePointer(args.Pointer))return;
draggingPointer=args.Pointer;args.Handled=true;UpdateDragVisual();DragStarted?.Invoke();
}
private void DragMoved(object sender,PointerRoutedEventArgs args)
{
if(draggingPointer?.PointerId!=args.Pointer.PointerId)return;
args.Handled=true;
if(!args.GetCurrentPoint(DragHandle).Properties.IsLeftButtonPressed){StopDragging();return;}
DragUpdated?.Invoke();
}
private void DragReleased(object sender,PointerRoutedEventArgs args)
{
if(draggingPointer?.PointerId!=args.Pointer.PointerId)return;
DragUpdated?.Invoke();StopDragging();args.Handled=true;
}
private void DragCanceled(object sender,PointerRoutedEventArgs args)
{if(draggingPointer?.PointerId==args.Pointer.PointerId)StopDragging();}
private void DragEntered(object sender,PointerRoutedEventArgs args){dragHovered=true;UpdateDragVisual();}
private void DragExited(object sender,PointerRoutedEventArgs args){dragHovered=false;UpdateDragVisual();}
private void UpdateDragVisual()
{
var active=draggingPointer is not null;
DragHandle.Background=active?dragActive:dragHovered?dragHover:dragNormal;
DragGrip.Background=active?gripActive:dragHovered?gripHover:gripNormal;
DragGrip.Width=active?44:dragHovered?40:36;
}
internal void StopDragging()
{
if(draggingPointer is not {} pointer)return;
draggingPointer=null;DragCompleted?.Invoke();DragHandle.ReleasePointerCapture(pointer);UpdateDragVisual();
}
private void Expand(object sender,RoutedEventArgs args)=>ExpandRequested?.Invoke();
private void Pin(object sender,RoutedEventArgs args)=>PinRequested?.Invoke();
private void Close(object sender,RoutedEventArgs args)=>CloseRequested?.Invoke();
private void Details(object sender,RoutedEventArgs args)=>DetailsRequested?.Invoke();
}
using XFEEDToolBox.ViewModels;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
namespace XFEEDToolBox.Views;
public sealed partial class UpgradeListContent : UserControl
{
public ToolboxViewModel ViewModel=>App.ViewModel;
public event Action? ExpandRequested,PinRequested,CloseRequested,DetailsRequested,DragStarted,DragUpdated,DragCompleted;
private bool floating,dragHovered;
private Pointer? draggingPointer;
private readonly SolidColorBrush dragNormal=new(Windows.UI.Color.FromArgb(8,255,255,255));
private readonly SolidColorBrush dragHover=new(Windows.UI.Color.FromArgb(20,255,255,255));
private readonly SolidColorBrush dragActive=new(Windows.UI.Color.FromArgb(34,255,255,255));
private readonly SolidColorBrush gripNormal=new(Windows.UI.Color.FromArgb(153,187,197,208));
private readonly SolidColorBrush gripHover=new(Windows.UI.Color.FromArgb(230,222,231,240));
private readonly SolidColorBrush gripActive=new(Windows.UI.Color.FromArgb(255,255,174,72));
public UpgradeListContent(){InitializeComponent();Unloaded+=(_,_)=>StopDragging();}
public void ConfigureFloating()
{
floating=true;ExpandListButton.Visibility=Visibility.Collapsed;
PinListButton.Visibility=CloseListButton.Visibility=DragHandle.Visibility=Visibility.Visible;
UpgradePreviewScroller.MaxHeight=double.PositiveInfinity;ToolTipService.SetToolTip(DragHandle,"按住拖动,松开停止");
}
public void ShowPinned(bool pinned)
{
PinListButton.Background=pinned?new SolidColorBrush(Windows.UI.Color.FromArgb(255,84,51,26)):new SolidColorBrush(Windows.UI.Color.FromArgb(0,0,0,0));
ToolTipService.SetToolTip(PinListButton,pinned?"取消置顶":"置顶");
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(PinListButton,pinned?"取消清单置顶":"置顶悬浮清单");
}
private void DragPressed(object sender,PointerRoutedEventArgs args)
{
if(!floating||draggingPointer is not null||!args.GetCurrentPoint(DragHandle).Properties.IsLeftButtonPressed)return;
if(!DragHandle.CapturePointer(args.Pointer))return;
draggingPointer=args.Pointer;args.Handled=true;UpdateDragVisual();DragStarted?.Invoke();
}
private void DragMoved(object sender,PointerRoutedEventArgs args)
{
if(draggingPointer?.PointerId!=args.Pointer.PointerId)return;
args.Handled=true;
if(!args.GetCurrentPoint(DragHandle).Properties.IsLeftButtonPressed){StopDragging();return;}
DragUpdated?.Invoke();
}
private void DragReleased(object sender,PointerRoutedEventArgs args)
{
if(draggingPointer?.PointerId!=args.Pointer.PointerId)return;
DragUpdated?.Invoke();StopDragging();args.Handled=true;
}
private void DragCanceled(object sender,PointerRoutedEventArgs args)
{if(draggingPointer?.PointerId==args.Pointer.PointerId)StopDragging();}
private void DragEntered(object sender,PointerRoutedEventArgs args){dragHovered=true;UpdateDragVisual();}
private void DragExited(object sender,PointerRoutedEventArgs args){dragHovered=false;UpdateDragVisual();}
private void UpdateDragVisual()
{
var active=draggingPointer is not null;
DragHandle.Background=active?dragActive:dragHovered?dragHover:dragNormal;
DragGrip.Background=active?gripActive:dragHovered?gripHover:gripNormal;
DragGrip.Width=active?44:dragHovered?40:36;
}
internal void StopDragging()
{
if(draggingPointer is not {} pointer)return;
draggingPointer=null;DragCompleted?.Invoke();DragHandle.ReleasePointerCapture(pointer);UpdateDragVisual();
}
private void Expand(object sender,RoutedEventArgs args)=>ExpandRequested?.Invoke();
private void Pin(object sender,RoutedEventArgs args)=>PinRequested?.Invoke();
private void Close(object sender,RoutedEventArgs args)=>CloseRequested?.Invoke();
private void Details(object sender,RoutedEventArgs args)=>DetailsRequested?.Invoke();
}