Search code examples
c#wpfnaudio

WPF slider thumb.DragCompleted


I'm learning from Mark Heath course of NAudio. I'm using a slider with the event:

Thumb.DragCompleted="SilderPositionOnDragCompleted"

And in the c#:

private void SilderPositionOnDragCompleted(object sender, System.Windows.Controls.Primitives.Thumb.DragCompleted e)
    {
            if (reader != null)
            {
                reader.CurrentTime = TimeSpan.FromSeconds(slider.Value);
            }
    }

I'm pretty sure that I wrote wrong the:

System.Windows.Controls.Primitives.Thumb.DragCompleted 

Because I have no idea what I need to write in there - I saw this here in the site.

are the errors: Here

What do I need to do?

Thanks!


Solution

  • Try this:

    private void SilderPositionOnDragCompleted(object sender, RoutedEventArgs e)
    {
        if (reader != null)
        {
            reader.CurrentTime = TimeSpan.FromSeconds(slider.Value);
        }
    }
    

    The type of the second argument should be RoutedEventArgs.

    And if you are hooking up the event handler programmatically you should use the following syntax:

    Thumb.DragCompleted += SilderPositionOnDragCompleted;
    

    ...where "Thumb" is the name of your Thumb:

    <Thumb x:Name="Thumb" />
    

    Or

    Thumb Thumb = ...;