Applying Style to a control automatically
In the previous two recipes, we learned about creating styles and applying them to controls by using the x:Key
name. It's not always feasible to manually assign the style to a set of huge controls within the same application. For this reason, we need to apply it automatically to all the elements within the scope of a specific window or the entire application.
For example, we may want all buttons within the same app to have the same look and feel. This makes creating new buttons easier, as the developer/designer doesn't have to know what style to apply. If the auto styling is configured, it will make the work far smoother.
Let's see how this can be done with a simple example.
Getting ready
To start this recipe, open your Visual Studio instance and create a new WPF application project called CH06.StyleUsageDemo
.
How to do it...
Follow these steps to create styles for button controls and apply them to controls within the same window, followed by applying...