Files
ShrlAlgoToolkit/AntdWpf/Controls/Thumb.cs
ShrlAlgo 4d35cadb56 更新
2025-07-11 09:20:23 +08:00

57 lines
1.6 KiB
C#

namespace AntdWpf.Controls
{
using System.Windows.Input;
using AntdWpf.Contracts;
using ThumbBase = System.Windows.Controls.Primitives.Thumb;
public class Thumb : ThumbBase, IThumb
{
private TouchDevice currentDevice = null;
protected override void OnPreviewTouchDown(TouchEventArgs e)
{
// Release any previous capture
this.ReleaseCurrentDevice();
// Capture the new touch
this.CaptureCurrentDevice(e);
}
protected override void OnPreviewTouchUp(TouchEventArgs e)
{
this.ReleaseCurrentDevice();
}
protected override void OnLostTouchCapture(TouchEventArgs e)
{
// Only re-capture if the reference is not null
// This way we avoid re-capturing after calling ReleaseCurrentDevice()
if (this.currentDevice != null)
{
this.CaptureCurrentDevice(e);
}
}
private void ReleaseCurrentDevice()
{
if (this.currentDevice != null)
{
// Set the reference to null so that we don't re-capture in the OnLostTouchCapture() method
var temp = this.currentDevice;
this.currentDevice = null;
this.ReleaseTouchCapture(temp);
}
}
private void CaptureCurrentDevice(TouchEventArgs e)
{
bool gotTouch = this.CaptureTouch(e.TouchDevice);
if (gotTouch)
{
this.currentDevice = e.TouchDevice;
}
}
}
}