Inherit control and change its style

1 Answer 117 Views
Styling
Marijana
Top achievements
Rank 1
Marijana asked on 19 Apr 2022, 03:38 PM

Hello Telerik team,

we are in trial period and exploring your product very seriously in past several days. We are interested in UI for Wpf line, but got stuck in choosing the way that is best for us and our product (lost in docs and demos to be honest). Tried  different approaches form your help, but did not manage to get it to work completely. Ended today with probably mixed implicit and explicit style options..

So, we want to have custom controls that inherit telerik's (watermarktext, datepicker, radio, combo and button for now).. These controls will have to implement some specific interfaces we need in application (not related to telerik) and also slightly override Telerik styles (for an example we want to change triggers for mouse move and focus on some of them..). At the same time, we want to apply material theme with our own color scheme (override default colors). What is the best way to do that? We would appreciate if you could provide some simple example to point us in right direction.

Thanks in advance!

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 20 Apr 2022, 12:14 PM

Hello Marijana,

To achieve your requirement you can use the following step:

  1. Create a class that inherits from the corresponding Telerik control. For example, RadComboBox.
  2. Define a Style targeting the custom control and add a Setter that sets its Template property. In order to apply the Style globally to all instances of your custom control, you can define it in App.xaml without x:Key. The missing x:Key will ensure that the Style is applied to all instances of the TargetType automatically. The fact that the Style is defined App.xaml will ensure that the Style scope will cover the entire application.
  3. Modify the default ControlTemplate of the Telerik control to match your needs.

I've attached a small example showing this approach. I hope that helps. Note that the example is based on the NoXaml dlls and Implicit Styles theming approach. This makes it easier to customize Styles and Templates because you don't need to copy the StaticResources they use from the default resources (from the associated .xaml file). Instead, the StaticResource keyword will access the resources from the merged dictionaries.

Also, you can take a look at the Styling the Controls and Missing Controls in the UI help article for possible issues and solution for this scenario.

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Marijana
Top achievements
Rank 1
commented on 20 Apr 2022, 01:08 PM

Hi Martin and thank you so much!

With your example I figured out in a sec what I was doing wrong.

Martin Ivanov
Telerik team
commented on 20 Apr 2022, 01:16 PM

Great to hear this.
Tags
Styling
Asked by
Marijana
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or