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

Custom inherited library

1 Answer 74 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Roberto
Top achievements
Rank 1
Roberto asked on 30 Jun 2010, 09:51 AM
Hi,

I'm trying to create a custom control library using telerik controls as base clases, and creating a default styleguide based on the default telerik styles for each control.

Basically, what I have (as if I was extending from standard WPF controls) is a ResourceDictionary (Generic.xaml) with a Targeted Style for each Custom Control, using the 'BasedOn' property. Something like this:

<Style BasedOn="{StaticResource {x:Type ComboBox}}"  
       TargetType="{x:Type local:MyComboBox}">  
        <Setter Property="Background" Value="Red" />  
        <Setter Property="Foreground" Value="DarkGray" />  
</Style> 



Regrettably, it seems this doesn't work out of the box with telerik, I mean, using RadComboBox as StaticResource. I've also tried using the ThemeResourceKey with no luck:

<Style TargetType="{x:Type local:MyComboBox}"  
               BasedOn="{StaticResource {telerik:ThemeResourceKey ThemeType=telerik:Office_BlackTheme, ElementType=Controls:RadComboBox}}">  
    <Setter Property="Background" Value="Red" />  
    <Setter Property="Foreground" Value="DarkGray" />  
</Style> 


The MyComboBox file looks like this:
public class MyComboBox : RadComboBox  
{  
        static MyComboBox ()  
        {  
            DefaultStyleKeyProperty.OverrideMetadata(typeof(MyComboBox), new FrameworkPropertyMetadata(typeof(MyComboBox)));  
        }  
}  


I also tried overriding the TargetType of the inherited control, again, no luck:

[LocalizabilityAttribute(LocalizationCategory.NeverLocalize)]  
[Ambient]  
public Type TargetType  
{  
    get { return typeof (RadComboBox);}   
}  

Any suggestions?

Thanks,

--
R.

1 Answer, 1 is accepted

Sort by
0
Pana
Telerik team
answered on 06 Jul 2010, 07:40 AM
Hello Roberto,

Everything looks cool. Only that for our theming we set DefaultStyleKey here and there... One of the places we do it is OnInitialized. You will need some more code in your class like:

protected override void OnInitialized(EventArgs e)
{
    base.OnInitialized(e); // Here we will set our default style key anyway...
    this.DefaultStyleKey = typeof(MyRadComboBox);
}

You can check the attached project for more details.

Regards,
Panayot
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
General Discussions
Asked by
Roberto
Top achievements
Rank 1
Answers by
Pana
Telerik team
Share this question
or