This is a migrated thread and some comments may be shown as answers.

Handling Events

4 Answers 76 Views
MediaPlayer
This is a migrated thread and some comments may be shown as answers.
Brandmuscle
Top achievements
Rank 1
Brandmuscle asked on 02 Aug 2009, 05:26 AM
I need to handle the MouseDown events on the Next/Prev buttons for the RadMediaPlayer.  How can I go about doing this?
I need to handle the MouseDown event for next, and while the mouse is down "DoWork()".  Same with previous.

Any help would be much appriciated.
  Thanks

4 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 03 Aug 2009, 07:44 AM
Hi Dan,

The easiest way to achieve what you are looking for, is to use the VisualTreeHelper class to retrieve the first visual element in RadMediaPlayer's ControlTemplate. After that you can use the FindName() method to get the buttons you are looking for. For better explanation please refer to the code bellow;

public MainPage() 
    InitializeComponent(); 
 
    Loaded += new RoutedEventHandler(MainPage_Loaded); 
 
void MainPage_Loaded(object sender, RoutedEventArgs e) 
    Dispatcher.BeginInvoke(() => 
    { 
        // Get the first visual element in RadMediaPlayer's ControlTemplate 
        FrameworkElement layoutRoot = VisualTreeHelper.GetChild(RadMediaPlayer1, 0) as FrameworkElement; 
        // The buttons responsible for navigating among the chapters are called NextChapterButton and PreviousChapterButton 
        Button nextChapterButton = layoutRoot.FindName("NextChapterButton"as Button; 
        Button previousChapterButton = layoutRoot.FindName("PreviousChapterButton"as Button; 
        // Silverlight 3 supports listening for already handled events. 
        nextChapterButton.AddHandler(FrameworkElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(ChapterButton_MouseLeftButtonDown), true); 
        previousChapterButton.AddHandler(FrameworkElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(ChapterButton_MouseLeftButtonDown), true); 
    }); 
 
private void ChapterButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
    // DoWork(); 

If you have additional questions, let us know.

Best wishes,
Kiril Stanoev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Brandmuscle
Top achievements
Rank 1
answered on 04 Aug 2009, 02:22 PM
Now the only problem is getting the buttons to not be disabled.  Is there any easy way to make them enabled at all times?
0
Brandmuscle
Top achievements
Rank 1
answered on 04 Aug 2009, 07:04 PM
found a work around for now.  enabling them after they get disabled.  not a perfect work around though.  any ideas would be helpful though.
0
Kiril Stanoev
Telerik team
answered on 05 Aug 2009, 07:33 AM
Hi Dan,

Unfortunately the only way to enable the buttons is only after they get disabled. What you can do in this case is to make nextChapterButton and previousChapterButton member variables, and in MediaOpened event handler of RadMediaPlayer to make then enabled.

Button nextChapterButton; 
Button previousChapterButton; 
 
public MainPage() 
    InitializeComponent(); 
    Loaded += new RoutedEventHandler(MainPage_Loaded); 
    RadMediaPlayer1.MediaOpened += new EventHandler<Telerik.Windows.RadRoutedEventArgs>(RadMediaPlayer1_MediaOpened); 
 
void RadMediaPlayer1_MediaOpened(object sender, Telerik.Windows.RadRoutedEventArgs e) 
    nextChapterButton.IsEnabled = true
    previousChapterButton.IsEnabled = true

For our next version of RadMediaPlayer we will make sure this gets fixed.
Let us know if you experience any additional questions.

Regards,
Kiril Stanoev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
MediaPlayer
Asked by
Brandmuscle
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Brandmuscle
Top achievements
Rank 1
Share this question
or