Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > DatePicker > Extending DatePicker problem

Answered Extending DatePicker problem

Feed from this thread
  • Posted on Jan 12, 2011 (permalink)

    I have the need to extend the DatePicker. I try to do this as I have done when I have extended the standard WPF controls (e.g. TextBox), but I have some problems. I can't make my extended control use its own template.

    The control has this code:
    public class DatePickerExtended : RadDatePicker
    {
        static DatePickerExtended()
        {
            //Make sure the style in Themes/Generic.xaml is used.
            DefaultStyleKeyProperty.OverrideMetadata(typeof(DatePickerExtended), new FrameworkPropertyMetadata(typeof(DatePickerExtended)));
        }
    }

    Then I have a folder in the root called "Themes" which contains a file called "Generic.xaml". This XAML file contains the template that i want to apply to the control:
    <Style TargetType="{x:Type local:DatePickerExtended}" x:Key="{x:Type local:DatePickerExtended}">
        <!-- A bunch of setters, including for the Template property. -->
    </Style>

    But the template is never applied. Instead the default template for the DatePicker is used, and I don't now how to replace this with my own...

    So the question is: How can I make my custom control inheriting from DatePicker use a custom template?

    Reply

  • Kaloyan Kaloyan admin's avatar

    Posted on Jan 13, 2011 (permalink)

    Hi David Haglund,

    Everything you have done is correct. In addition make sure that the style is in a Generic.xaml file under a Theme folder in your project. You can also try to include the declared style in the app resources. Let us know if this is not helping you.

    Greetings,
    Kaloyan
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>

    Reply

  • Posted on Jan 14, 2011 (permalink)

    I have a folder called "Themes" in the root containing "Generic.xaml". And this file works fine for another control I'm extending (standard TextBox). But my style/template for RadDatePicker just won't apply! Do you have any test project where you have succesfully extended the RadDatePicker and given it another template?

    Reply

  • Kaloyan Kaloyan admin's avatar

    Posted on Jan 14, 2011 (permalink)

    Hello David Haglund,

    Find the attached sample.

    Best wishes,
    Kaloyan
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
    Attached files

    Reply

  • Posted on Jan 19, 2011 (permalink)

    Well...that works. But that's an ordinary default style that you make a reference to in App.xaml. My point is that when I've extended the standard controls (such as TextBox) I've always just put my own default style/template in a file called "Themes\Generic.xaml", and then it gets applied automaitcally without me having to make references to it anywhere. That's the whole point with using Generic.xaml; otherwise I could put it in any XAML-resource file.

    In your example project you do have the codeline that hooks up the extended control to it's default style/template, but that doesn't actually do anything since there is no Themes-folder. So I can remove the codeline and it doesn't matter.

    By using the Generic.xaml approach I can put all my extended controls and their templates in one assembly and use them in as many other assemblies as I like, without having to make references to any styles.

    Is it not possible to do this when extending Telerik controls?

    Reply

  • Answer Kaloyan Kaloyan admin's avatar

    Posted on Jan 21, 2011 (permalink)

    Hello David Haglund,

    In that case you have to override the OnInitialized method as well:

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

     
    Greetings,
    Kaloyan
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>

    Reply

  • Posted on Jan 24, 2011 (permalink)

    Thanks Kaloyan, that works fine. :)

    Reply

  • prithu avatar

    Posted on Feb 8, 2012 (permalink)

    Hi David and Kaloyan,
                                        I have the exact problem as David. The style in generic.xaml is never applied. When I copy paste the same style in App.xaml the style is applied the 2nd time the control is used. The fist time the control is displayed with default style.

    Hi David.. were u able to solve the problem?

    Best regards,
    prithu

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > DatePicker > Extending DatePicker problem
Related resources for "Extending DatePicker problem"

WPF DatePicker Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]