Hello!
There is a homemade video slider.
Theme with slider
So, I want to make that when you click on the slider rewind at that time, which corresponds to the value of the slider.
Here is the code:
private void slider_MouseDown(object sender, MouseButtonEventArgs e) { float percentTime = ( (float)e.GetPosition(slider).X / (float)slider.Width ) * 100; pos = (float)media.NaturalDuration.TimeSpan.TotalSeconds / 100 * percentTime; media.Position = new TimeSpan(0, 0, (int)pos); text.Text = e.GetPosition(slider).X.ToString(); } With the calculations, everything is fine. The problem is that it crashes because the number is NaN.
As you can see in the code, I displayed the numbers in the TextBox for verification and they are normal, not NaN.
Before clicking have their numeric types.
NaN is converted by clicking on the slider.
There is no division by zero.
The first time I ran into this and what to do is not clear.
slider.Width? - VladD