更新
This commit is contained in:
59
WPFDark/StandardControls/ScrollViewerEventHandler.cs
Normal file
59
WPFDark/StandardControls/ScrollViewerEventHandler.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using WPFDark.Internals;
|
||||
|
||||
|
||||
namespace WPFDark.StandardControls
|
||||
{
|
||||
public partial class ScrollViewerEventHandler
|
||||
{
|
||||
private const double Response = 150.0;
|
||||
private const double MaxOpacity = 0.6;
|
||||
private const double BarWidth = 8.0;
|
||||
|
||||
private void OnPreviewMouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
var self = ((FrameworkElement) sender).GetParent<ScrollViewer>();
|
||||
|
||||
if (self is null)
|
||||
return;
|
||||
|
||||
var pos = e.GetPosition(self);
|
||||
var posX = pos.X;
|
||||
var posY = pos.Y;
|
||||
|
||||
var width = (1.0, self.ActualWidth - BarWidth).Max();
|
||||
var height = (1.0, self.ActualHeight - BarWidth).Max();
|
||||
|
||||
if (ScrollViewerAttachedProperties.GetIsLeftVerticalScrollBar(self))
|
||||
posX = width - posX;
|
||||
|
||||
var xr = (Response, width).Min();
|
||||
var yr = (Response, height).Min();
|
||||
|
||||
var xir = width - xr;
|
||||
var yir = height - yr;
|
||||
|
||||
var xd = NumberHelper.Clamp01((posX - xir) / xr);
|
||||
var yd = NumberHelper.Clamp01((posY - yir) / yr);
|
||||
|
||||
var xo = xd * MaxOpacity;
|
||||
var yo = yd * MaxOpacity;
|
||||
|
||||
ScrollViewerAttachedProperties.SetVerticalScrollBarOpacity(self, xo);
|
||||
ScrollViewerAttachedProperties.SetHorizontalScrollBarOpacity(self, yo);
|
||||
}
|
||||
|
||||
private void OnMouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
var self = ((FrameworkElement) sender).GetParent<ScrollViewer>();
|
||||
|
||||
if (self is null)
|
||||
return;
|
||||
|
||||
ScrollViewerAttachedProperties.SetVerticalScrollBarOpacity(self, 0.0);
|
||||
ScrollViewerAttachedProperties.SetHorizontalScrollBarOpacity(self, 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user