Why do you need to do it from code? There is an alternative which I describe
here[
^]. By doing this, you have one
DataTemplate
(which controls the conditions for switching the templates), and you change the other
DataTemplate
s to
ControlTemplate
s.