银色滑块控制

时间:2010-05-04 06:19:43

标签: silverlight silverlight-3.0

我在silverlight应用程序中为音频播放器使用滑块控件。播放音频时滑块不移动。 下面是我的XAML代码。如何获得它?

<Slider x:Name="Slider" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" 
  MouseLeftButtonDown="MouseClicked" MouseLeftButtonUp="MouseReleased" 
  ValueChanged="Slider_ValueChanged" Height="30" Width="484"   ></Slider>

滑块事件的代码隐藏:

private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
  {
     Audio.Pause();
     Audio.Position = TimeSpan.FromSeconds(Slider.Value);
     Audio.Play();
  }

  private void MouseClicked(object sender, MouseButtonEventArgs e)
  {
     Audio.Pause();
     Audio.Position = TimeSpan.FromSeconds(Slider.Value);
  }

  private void MouseReleased(object sender, MouseButtonEventArgs e)
  {
     Audio.Play();
  }

1 个答案:

答案 0 :(得分:1)

在Silverlight 3中(据我所知)MouseLeftButtonDown无效。您需要在代码中创建自己的Handler。例如:

progress_bar.AddHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler(progress_bar_MouseLeftButtonDown), true);