views:

537

answers:

1

hi there,

i wonder if there is a way to access a control's templatepart from within c# for modifying the part (e.g. hiding, etc..). is it possible to get a reference to the part with pure c#? i don't want to touch the controls template. thanks j.

+2  A: 

It is possible, but its quite nasty.

On the Template there is a method called FindName, which needs two arguments: the name and the FrameworkElement that has the ControlTemplate as Template. Of course, you need to set the name of the element in the ControlTemplate...

Another more elegent solution is to use a Binding in the ControlTemplate to determine the visibility.. That way you do not need to do stuff in your code behind and you can keep it Xaml only...

Arcturus