Skip to content

Latest commit

 

History

History
36 lines (27 loc) · 880 Bytes

kb-common-create-implicit-style-in-code.md

File metadata and controls

36 lines (27 loc) · 880 Bytes
title description type page_title slug position tags ticketid res_type
How to Create Implicit Style in Code
How to Add Implicit Style in code-behind.
how-to
How to Define Implicit Style in Code
kb-common-create-implicit-style-in-code
0
resources,typeof,xkey
1404933
kb

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.

[C#]

{{region kb-common-create-implicit-style-in-code}} public MainWindow() { InitializeComponent();

	Style style = new Style(typeof(Button));
	style.Setters.Add(new Setter(Button.ForegroundProperty, Brushes.Red));

	this.Resources.Add(typeof(Button), style);
}

{{endregion}}