New to Telerik UI for WPF? Download free 30-day trial

How to Create Implicit Style in Code

Environment

This is common information applicable to the WPF framework in general.

Description

How to create an implicit style in code.

Solution

Call the Add method of the corresponding Resources collection with the target type as first argument and the Style object as second.

public MainWindow() 
{ 
    InitializeComponent(); 
 
    Style style = new Style(typeof(Button)); 
    style.Setters.Add(new Setter(Button.ForegroundProperty, Brushes.Red)); 
 
    this.Resources.Add(typeof(Button), style); 
} 
In this article