How to override theme for custom control

2 posts, 0 answers
  1. Jerry
    Jerry avatar
    10 posts
    Member since:
    Mar 2013

    Posted 12 Jul 2016 Link to this post

    In our Silverlight app, we have a container view that defines a merged dictionary that points to the following themes:

    <ResourceDictionary Source="/Telerik.Windows.Themes.Metro;component/Themes/System.Windows.xaml"/>
    <ResourceDictionary Source="/Telerik.Windows.Themes.Metro;component/Themes/Telerik.Windows.Controls.xaml"/>
    <ResourceDictionary Source="/Telerik.Windows.Themes.Metro;component/Themes/Telerik.Windows.Controls.Input.xaml"/>
    <ResourceDictionary Source="/Telerik.Windows.Themes.Metro;component/Themes/Telerik.Windows.Controls.Navigation.xaml"/>
    <ResourceDictionary Source="/Telerik.Windows.Themes.Metro;component/Themes/Telerik.Windows.Controls.GridView.xaml"/>


    All the user control views that display in the container inherit these themes.

    The problem we have is that when we insert one of our custom controls onto any of these user control views, the custom control doesn't appear correct. This custom control is made up of a textbox, popup and button. The textbox backgrond appears transparent instead of grey.

    Is there a way to override our custom control look and feel from what the above themes are doing to this control?








  2. Martin
    Martin avatar
    126 posts

    Posted 13 Jul 2016 Link to this post

    Hi Jerry,

    If I understand you correctly, the way to prevent a certain control from being styled by the Telerik themes, but preserve the style for the rest of the application, is to set specific Style for your custom control.

    You can extract the default windows styles for the components you are using (in your case TextBox, Button and Popup) and integrate them in the UserControl Resources. But keep in mind that setting a custom style on any control and not Basing it on the Telerik styles will result in completely overriding the theme style for it and applying the specified style.

    The other approach is to create a style for the whole control and define its children inside, with references to their native styles (they need to be present as resources as well). This way you can have one style tag in your application resources with a target your control which will style all its instances.

    You can also consider to remove the default Telerik theming of the native WPF controls as TextBox, Button, etc. To do that just delete the ResourceDictionary that points to the System.Windows.xaml file.

    You can review this article in MSDN for default ControlTemplates of most of the native controls and this thread in Stack Overflow about extracting a default ControlTemplate.

    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top