我想知道如何让滑块拇指跳到我点击滑块的位置。换句话说,如何检索用户在滑块上单击的值(然后我可以设置滑块的值)。
这个问题就像:
Slider control with Move-To-Position behavior
但是没有可用的解决方案。
由于wp7中的滑块控件没有 IsMoveToPointEnabled 属性,因此自定义是获取IMO功能的唯一方法。我使用following codes:
public class CustomSlider: Slider {
public CustomSlider() {
DefaultStyleKey = typeof (Slider);
}
public override void OnApplyTemplate() {
base.OnApplyTemplate();
RepeatButton rb;
rb = base.GetTemplateChild("HorizontalTrackLargeChangeIncreaseRepeatButton") as RepeatButton;
rb.MouseMove += new MouseEventHandler(rb_MouseMove);
rb.Click += new RoutedEventHandler(rb_Click);
rb = base.GetTemplateChild("HorizontalTrackLargeChangeDecreaseRepeatButton") as RepeatButton;
rb.MouseMove += new MouseEventHandler(rb_MouseMove);
rb.Click += new RoutedEventHandler(rb_Click);
rb = base.GetTemplateChild("VerticalTrackLargeChangeIncreaseRepeatButton") as RepeatButton;
rb.Click += new RoutedEventHandler(rb_Click);
rb.MouseMove += new MouseEventHandler(rb_MouseMove);
rb = base.GetTemplateChild("VerticalTrackLargeChangeDecreaseRepeatButton") as RepeatButton;
rb.Click += new RoutedEventHandler(rb_Click);
rb.MouseMove += new MouseEventHandler(rb_MouseMove);
//rb.
}
Point ps;
void rb_MouseMove(object sender, MouseEventArgs e) {
ps = e.GetPosition(this);
}
public event EventHandler MyClickEvent;
void rb_Click(object sender, RoutedEventArgs e) {
if (MyClickEvent != null) MyClickEvent(this, new PositionEventArgs(ps));
}
}
public class PositionEventArgs: EventArgs {
public Point Position {
set;
get;
}
public PositionEventArgs() {}
public PositionEventArgs(Point p) {
Position = p;
}
}
我尽我所能,但直到现在,我都无法让它发挥作用。嵌入滑块中的 RepeatButton 上的 MOUSEOVER 事件永远不会触发,即使xaml中单独存在 RepeatButton 。事实上,只是点击事件在我的实验中被触发。
我看到大多数视频播放器都有此功能,所以我真的想知道如何在播放器中制作它。