tags:

views:

766

answers:

2

Hey all!

I'm trying to create a pimped-out version of the slider that has a user control in the "thumb"-part (meaning: the moving thingy on the slider) that reacts to the slider's movements. Basically my current demo / development version is just a UserControl with 5 visual states that just make it change a smiley face to an angry face in 5 phases. I'd like to put that user control into the thumb.

My only problem is as follows: I can get the UserControl into the thumb no problem, by editing the Slider-control's template in Expression Blend. However, once the UserControl is in the ControlTemplate, it's no longer visible to the new user control class and thus is not changeable with VisualStateManager.

So basically, my question is two-fold:

1) Is there any better way to replace the thumb of the Slider-control than editing it's template?

2) If not, how can I access stuff I've added to the template?

Thanks for any answers!

+1  A: 

I'm answering myself. After visiting every single page on the internet, I finally figured out a solution by myself!

I added a Loaded-event handler to my control in the ControlTemplate and in that event handler I took the reference to that control for the actual class! After that I was able to refer to that control with that reference and for example visualstate changes worked like a charm!

I've now got a hopped-up slider that has a smiley in the handle part and the face on the smiley changes in relation to the position of the slider! Pretty cool!

Great! It would be in the spirit of Stack Overflow if you posted your code and showed us all how you did it.
Timothy Lee Russell
A: 

I worked it from a different angle: You can override the OnApplyTemplate() and get your reference with the GetTemplateChild methode. It somehow feels cleaner