我玩了一些模板,但看起来你是对的——如果你拖动拇指——你会得到拖动事件,但如果你开始在其他地方拖动——你能得到的最好的就是一些指针事件。也许你可以得到这些,但你可能只需要限制事件。
这是我尝试过的:
using System.Linq;
using WinRTXamlToolkit.Controls.Extensions;
using WinRTXamlToolkit.Debugging;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Shapes;
namespace App91
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.Loaded += OnLoaded;
}
private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
//WinRTXamlToolkit.Controls.Extensions.VisualTreeHelperExtensions.GetFirstDescendantOfType<>()
var horizontalTemplateGrid =
s1.GetDescendantsOfType<Grid>()
.First(g => g.Name == "HorizontalTemplate");
horizontalTemplateGrid.PointerPressed += OnPointerPressed;
horizontalTemplateGrid.PointerReleased += OnPointerReleased;
horizontalTemplateGrid.PointerMoved += OnPointerMoved;
var rect =
s1.GetDescendantsOfType<Rectangle>()
.First(g => g.Name == "HorizontalTrackRect");
rect.PointerPressed += OnPointerPressed;
rect.PointerReleased += OnPointerReleased;
rect.PointerMoved += OnPointerMoved;
rect =
s1.GetDescendantsOfType<Rectangle>()
.First(g => g.Name == "HorizontalDecreaseRect");
rect.PointerPressed += OnPointerPressed;
rect.PointerReleased += OnPointerReleased;
rect.PointerMoved += OnPointerMoved;
var thumb = s1.GetFirstDescendantOfType<Thumb>();
thumb.DragStarted += ThumbOnDragStarted;
thumb.DragCompleted += ThumbOnDragCompleted;
thumb.PointerPressed += OnPointerPressed;
thumb.PointerReleased += OnPointerReleased;
this.PointerPressed += OnPointerPressed;
this.PointerReleased += OnPointerReleased;
}
private void OnPointerMoved(object sender, PointerRoutedEventArgs pointerRoutedEventArgs)
{
if (pointerRoutedEventArgs.Pointer.IsInContact)
{
DC.Trace("Pointer Moved");
}
}
private void OnPointerReleased(object sender, PointerRoutedEventArgs pointerRoutedEventArgs)
{
DC.Trace(
"Pointer Released on " +
pointerRoutedEventArgs.OriginalSource.GetType() +
" named " +
((FrameworkElement)pointerRoutedEventArgs.OriginalSource).Name);
}
private void OnPointerPressed(object sender, PointerRoutedEventArgs pointerRoutedEventArgs)
{
DC.Trace(
"Pointer Pressed on " +
pointerRoutedEventArgs.OriginalSource.GetType() +
" named " +
((FrameworkElement)pointerRoutedEventArgs.OriginalSource).Name);
}
private void ThumbOnDragCompleted(object sender, DragCompletedEventArgs dragCompletedEventArgs)
{
DC.Trace("Drag Completed");
}
private void ThumbOnDragStarted(object sender, DragStartedEventArgs dragStartedEventArgs)
{
DC.Trace("Drag Started");
}
private void S1_OnValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
DC.Trace("Value Changed");
}
}
}