tags:

views:

159

answers:

2

I'm using a slider control in WPF to show how much of a file has been read, and to control where to read the file from.

The slider binds its Value to a int ProgressValue. I use a timer to look at the current read percentage and set the ProgressValue appropriately. The slider moves to the desired position. As more of the file is read, the slider moves to the right.

But how do I detect that the user has clicked on the slider and is moving it around, so I can seek my file to the desired offset? I tried to add handlers to MouseLeftButtonDown, DragEnter, DragLeave and DragOver but they don't get called when I click and drag the slider around. This is the current slider's XAML:

<Slider x:Name="sliderProgress" TickPlacement="BottomRight" TickFrequency="1000" Minimum="0" Maximum="1000" Value="{Binding ProgressValue1000}" Style="{DynamicResource SliderStyle1}" HorizontalAlignment="Left" Width="478" MouseLeftButtonDown="onSliderLeftButtonDown" />
+1  A: 

You have to add handler for the ValueChanged event in order to get the current value of the slider when the user moves it around. then you can find the new value of the slider by using the e.NewValue parameter of the event.

Nima Rikhtegar
A: 

Why can't to you use the bound property 'ProgressValue'? The change made by the user is ready for you in that property, as any UserEditable control binds TwoWay by default and updates source when its property changes.

Once the user changes the value of the slider, the change is propagated to the bound property 'ProgressValue'. Now you can use this property to seek your file.

Veer