滑块 - 无需单击拇指即可更改值
Slider - change value without clicking thumb
我试图在不点击拇指的情况下移动滑块。我现在所拥有的是单击滑块并将拇指移动到该位置。我想要做的是当鼠标点击仍然向下时能够移动拇指(更改值)。 (就像在 YouTube 或任何 audio/video 播放器上一样)
这是我现在拥有的:
<Slider MouseLeave="Slider_MouseLeave"
MouseMove="Slider_MouseMove"
IsMoveToPointEnabled ="True"
PreviewMouseUp="Slider_PreviewMouseUp"
Thumb.DragStarted="Slider_DragStarted"
Thumb.DragCompleted="Slider_SaveChange"
Minimum="0"
Maximum="{Binding HomeViewSettings.SelectedTrack.TrackTime.TotalSeconds}"
Value="{Binding HomeViewSettings.CurrentTrackProgressInValue}"/>
我找到了这个解决方案:
mySlider.MouseMove += (sender, args) =>
{
if (args.LeftButton == MouseButtonState.Pressed && this.clickedInSlider)
{
var thumb = (mySlider.Template.FindName("PART_Track", mySlider) as System.Windows.Controls.Primitives.Track).Thumb;
thumb.RaiseEvent(new MouseButtonEventArgs(args.MouseDevice, args.Timestamp, MouseButton.Left)
{
RoutedEvent = UIElement.MouseLeftButtonDownEvent,
Source = args.Source
});
}
};
mySlider.AddHandler(UIElement.PreviewMouseLeftButtonDownEvent, new RoutedEventHandler((sender, args) =>
{
clickedInSlider = true;
}), true);
mySlider.AddHandler(UIElement.PreviewMouseLeftButtonUpEvent, new RoutedEventHandler((sender, args) =>
{
clickedInSlider = false;
}), true);
我试图在不点击拇指的情况下移动滑块。我现在所拥有的是单击滑块并将拇指移动到该位置。我想要做的是当鼠标点击仍然向下时能够移动拇指(更改值)。 (就像在 YouTube 或任何 audio/video 播放器上一样) 这是我现在拥有的:
<Slider MouseLeave="Slider_MouseLeave"
MouseMove="Slider_MouseMove"
IsMoveToPointEnabled ="True"
PreviewMouseUp="Slider_PreviewMouseUp"
Thumb.DragStarted="Slider_DragStarted"
Thumb.DragCompleted="Slider_SaveChange"
Minimum="0"
Maximum="{Binding HomeViewSettings.SelectedTrack.TrackTime.TotalSeconds}"
Value="{Binding HomeViewSettings.CurrentTrackProgressInValue}"/>
我找到了这个解决方案:
mySlider.MouseMove += (sender, args) =>
{
if (args.LeftButton == MouseButtonState.Pressed && this.clickedInSlider)
{
var thumb = (mySlider.Template.FindName("PART_Track", mySlider) as System.Windows.Controls.Primitives.Track).Thumb;
thumb.RaiseEvent(new MouseButtonEventArgs(args.MouseDevice, args.Timestamp, MouseButton.Left)
{
RoutedEvent = UIElement.MouseLeftButtonDownEvent,
Source = args.Source
});
}
};
mySlider.AddHandler(UIElement.PreviewMouseLeftButtonDownEvent, new RoutedEventHandler((sender, args) =>
{
clickedInSlider = true;
}), true);
mySlider.AddHandler(UIElement.PreviewMouseLeftButtonUpEvent, new RoutedEventHandler((sender, args) =>
{
clickedInSlider = false;
}), true);