views:

17

answers:

0

I have a custom lookless control derived from Control. The "goal" was to have my custom control be a tab control with two predefined tabs, some controls within each tab, and a contentpresenter within each tab where the developer can put their own stuff. I have a dependency property and binding for each content presenter, and it does work, except the user can't switch tabs at design time to enter content into the second contentpresenter. They have to manually enter their stuff into the xaml for the second contentpresenter.

So now I'm trying to have two different controltemplates, one for run-time and one for design-time. The design-time one would just show both contentpresenters up front and the runtime one would include the tab.

So I modified my current contenttemplate to have a key called "Runtime" and I made a new controltemplate without a key and without the tab. The one without the key loads fine for designtime and the developer can edit within each contentpresenter. But when I run the app, I can't get any other controltemplate loaded.

Here are variations of what I was trying:

if (DesignerProperties.GetIsInDesignMode(this)) { this.DefaultStyleKey = typeof(MyCustomControl); } else { //this.DefaultStyleKey = typeof(MyCustomControl); //this.SetResourceReference(MyCustomControl.TemplateProperty, "{StaticResource Runtime}"); //Style style = (Style)FindResource("Runtime"); //this.SetValue(MyCustomControl.TemplateProperty, "{DynamicResource Runtime}"); }

Nothing works.

How does one dynamically specify a control template at runtime?