我想知道如何使滑块拇指跳到我单击滑块的位置。换句话说,我如何检索用户单击滑块的值(然后我可以设置滑块的值)。
这个问题就像:
但是没有可用的解决方案。
因为 wp7 中的滑块控件没有IsMoveToPointEnabled属性,所以自定义是获得功能 IMO 的唯一方法。我使用以下代码:
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事件永远不会触发,即使RepeatButton在 xaml 中单独存在。事实上,在我的实验中只触发了CLICK事件。
我看到大多数视频播放器都有这个功能,所以我真的很想知道如何在我的播放器中制作它。