There are 2 ways to perform style on a control in WPF application,
- Using separate style file
- Add the style on the same page
Now I will show you a demo to access the style on a button using both ways.
Note: In this article I am using Visual Studio 2015.
Step 1 - Create a project named ‘WpfTestApplication’ of WPF application.

Step 2 - It’s a better approach to create the folder named ‘css’ in the project to store the style files.

Step 3 - Add a Resource Dictionary named ‘MyStyle.xaml’ in the css folder.

Step 4 - Add the below code in ResourceDictionary tag, where,
- ‘Key’ is the style’s unique name.
- ‘TargetType’ tells about the target control type.
- In the setter, property means what behavior you want to change.
- In the setter, value means what will be the value of behavior.
- <Style x:Key="RedGradientBtn" TargetType="Button">
- <Setter Property="Control.Foreground" Value="White" />
- <Setter Property="Control.Background" Value="Maroon" />
- </Style>

Step 5 - Add the code into the auto generated page named ‘MainWindow.xaml’ to access the resource dictionary file which exists in the css folder means MyStyle.xaml file.



Vignesh ManiPosted May 6, 2016, 5:00 PM
nice one
Neeraj KumarPosted May 6, 2016, 4:30 PM
Good
Kuppurasu NagarajPosted May 6, 2016, 9:10 AM
Nice Sharing..
Debasis SahaPosted May 6, 2016, 5:25 AM
Good One..
Sr KarthigaPosted May 6, 2016, 3:37 AM
good one
Raja TPosted May 6, 2016, 2:53 AM
Nice,Thanks for sharing
Anbu ManiPosted May 6, 2016, 2:33 AM
Superb
Thiruppathi RPosted May 6, 2016, 1:44 AM
Nice One..