I know the way to add it in .xaml file, but I need the way to add it in C# file. Thanks.
Asked
Active
Viewed 2,047 times
2 Answers
1
You find how to get the Thumb
programmatically here.
Then just add the Handler to event:
sliderThumb.DragCompleted += myDragCompletedHandler;

Community
- 1
- 1

Miklós Balogh
- 2,164
- 2
- 19
- 26
-
Thanks! But now the 1st problem I meet is that the slider.Template is null and I don't konw why. – Cuero Sep 21 '12 at 00:44
-
I init the slider programmatically, so should I do sth. to init slider.Template? – Cuero Sep 21 '12 at 00:48
-
slider.Template is null till the slider is rendered on the screen. See [this](http://stackoverflow.com/questions/1080375/force-rendering-of-a-wpf-control-in-memory) how to force rendering in memory – Miklós Balogh Sep 21 '12 at 07:42
0
This is the simplest solution I could find without messing with the Thumb
property:
slider.AddHandler(Thumb.DragCompletedEvent, new DragCompletedEventHandler((sender, e) =>
{
// Handling code
}));

tuanh118
- 311
- 2
- 5