Accessing UserControls in ControlTemplates (Silverlight)

I'm trying to create a raised version of a slider that has a custom thumb control (which means: a moving thing on the slider) that responds to movement of the slider. Basically my current demo / development version is just a UserControl with 5 visual states that just makes it change smiley to angry face in 5 phases. I would like to put this custom control on my thumb.

My only problem is this: I can get the UserControl in the thumb without any problem by editing the slider control template in Expression Blend. However, once the UserControl is in the ControlTemplate, it will no longer be visible to the new user control class and therefore not modified by the VisualStateManager.

So basically my question is twofold:

  • Is there a better way to replace the thumb of a slider control than to edit it?

  • If not, how can I access the stuff I added to the template?

Thanks for any answers!

+1


source to share


2 answers


I answer myself. After visiting every page on the internet, I finally figured out the solution on my own!

I added a Loaded event handler to my control in the ControlTemplate, and in that event handler, I took a reference to that control for the actual class! After that, I was able to reference this control using this link, and for example the changes to the visual worked like a charm!



I now have a sliding slider with an emoji in the pen and the face on the emoji changes relative to the position of the slider! Pretty cool!

+1


source


I worked from a different angle: You can override OnApplyTemplate () and get your link using the GetTemplateChild method. It somehow feels cleaner



0


source







All Articles