Handling Events

5 posts, 0 answers
  1. Brandmuscle
    Brandmuscle avatar
    19 posts
    Member since:
    Nov 2008

    Posted 02 Aug 2009 Link to this post

    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
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 03 Aug 2009 Link to this post

    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.
  3. DevCraft banner
  4. Brandmuscle
    Brandmuscle avatar
    19 posts
    Member since:
    Nov 2008

    Posted 04 Aug 2009 Link to this post

    Now the only problem is getting the buttons to not be disabled.  Is there any easy way to make them enabled at all times?
  5. Brandmuscle
    Brandmuscle avatar
    19 posts
    Member since:
    Nov 2008

    Posted 04 Aug 2009 Link to this post

    found a work around for now.  enabling them after they get disabled.  not a perfect work around though.  any ideas would be helpful though.
  6. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 05 Aug 2009 Link to this post

    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.
Back to Top
DevCraft banner