This is a migrated thread and some comments may be shown as answers.

Overriding Control Template in a Custom Control Library not working

1 Answer 441 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Eric Bush
Top achievements
Rank 1
Eric Bush asked on 30 Jul 2010, 10:33 PM
I have the following derivation that includes the customary static constructor.

 

public class CustomRadDatePicker : RadDatePicker

 

 

static CustomRadDatePicker()

 

{

DefaultStyleKeyProperty.OverrideMetadata(

 

typeof(CustomRadDatePicker),

 

 

new FrameworkPropertyMetadata(typeof(CustomRadDatePicker))); // also tried RadDatePicker here

 

}

In the XAML for the controls template I have the following.

 

 

 

<Style TargetType="{x:Type SharedControls:CustomRadDatePicker}">
...

 

 

 

<Setter Property="Template">

 

 

 

 

 

 

<Setter.Value>

 

 

 

 

 

 

<ControlTemplate TargetType="{x:Type SharedControls:CustomRadDatePicker}">

Now when I use the control on a page it does not use the style I have set up but is using the Telerik style.
I have my derived control and its template set up in a WPF custom control library.
Is it allowed to override the Teleric Style?

-eric

 

1 Answer, 1 is accepted

Sort by
0
George
Telerik team
answered on 05 Aug 2010, 09:15 AM
Hi Eric Bush,

Thank you for contacting us.
 
You could override OnInitialized method, call the base OnInitialized and after that set the DefaultStyleKey.
For example: 

protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);
            this.DefaultStyleKey = typeof(CustomRadDatePicker);
        }

I hope this helps!

Best wishes,
George
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
DatePicker
Asked by
Eric Bush
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or