Creating the Style of a control based on another Style
Styles support inheritance. That means, you can derive a Style
from another Style
. This can be done using the BasedOn
property, which must point to another Style
to inherit from. In this recipe, we will learn how to create a Style
of a button control based on another Style
of the same type.
Getting ready
Let's get started by creating a project named CH06.StyleInheritanceDemo
. To do this, open your Visual Studio instance and create a project based on the WPF application template.
How to do it...
Follow these steps to create a base style for a button control and then derive it to create different button styles:
- Open the
MainWindow.xaml
file and create a<Window.Resources></Window.Resources>
section inside theWindow
tag. - Now, inside the window resources, add the following style definition, which we discussed in the previous recipe of this chapter:
<Style x:Key="ButtonBaseStyle" TargetType="{x:Type Button}"> <...