views:

15

answers:

1

I am extending the WPF Calendar control, and I have copied the control templates for the Calendar, CalendarItem, CalendarButton, and CalendarDayButton to the Generic.xaml of my custom control. The TargetType for the Calendar control template is my custom control, FsCalendar:

<!-- Calendar Control Template -->
<Style TargetType="{x:Type local:FsCalendar}">
...
</Style>

But what about the other control templates? Do I leave them targeted at the original Calendar, like this?

<!-- CalendarDayButton Control Template -->
<Style TargetType="CalendarDayButton">
...
</Style>

Or do I target it to my custom control? If so, how would I do that?

I tried putting my namespace (local) in the declaration, but that didn't work. So, as it stands, the TargetType is set to the default System.Windows.Controls.Primitives namespace.

Thanks for your help.

+1  A: 

If you're still using the same objects from the original, i.e. haven't created a new FsCalendarDayButton, you just need the original TargetTypes exactly as you copied them.

If you want to change the templates for them whenever they're used in your FsCalendar you can either add x:Key to each of them and then add StaticResource references on each usage (might not be practical if they're nested or auto-generated instances) in your FsCalendar template or leave them as implicitly typed with just a TargetType and move them into the Resources of your Style or ControlTemplate so they'll get pulled along whenever that Style is loaded.

If you aren't modifying those controls then you don't need the copies of their Styles at all - the defaults will be picked up when you use the controls, just like a Button or ComboBox.

John Bowen
Thanks, John--accepted and +1.
David Veeneman