1

I have a UserControl in my application that uses a template like so:

<UserControl> ...
 Template="{DynamicResource MyTemplate}"
</UserControl>

The template is defined in the same XAML file and it is working fine. My problem is that I do not want the template to be active all the time. I would need to programatically disable and enable it when neccessary.

I have already tried:

userControl.Template = null;

but this will make the entire user control dissapear.

Any ideas?

Tseng
  • 61,549
  • 15
  • 193
  • 205
Ricardo Mota
  • 1,194
  • 2
  • 12
  • 25
  • your question is not clear..i hope its like you need to use 2 templates at different times. is that your question? – Joseph Jul 09 '15 at 09:45
  • Yes, I have done some changes. Ive created two templates in the App.xaml instead of having them in the UserControl XAML. I'm now able to switch between templates. The problem is that I cannot create an "empty" template. – Ricardo Mota Jul 09 '15 at 10:32
  • great.if you have any more doubts please refer this link http://stackoverflow.com/questions/27326813/wpf-changing-contenttemplate-in-usercontrol-by-trigger – Joseph Jul 09 '15 at 10:50

2 Answers2

1

You have to provide a fully created template, not set it to null. Create an "empty" template, and set it at userControl.Template = null;. To check the default templates, there is an answere here.

Community
  • 1
  • 1
ntohl
  • 2,067
  • 1
  • 28
  • 32
0

Resolved

Needed to get the default template of my UserControl.

Thank you @ntohl and @Joseph.

Community
  • 1
  • 1
Ricardo Mota
  • 1,194
  • 2
  • 12
  • 25