Style.BasedOn Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets or sets a defined style that is the basis of the current style.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
<object BasedOn="styleReference" .../>
XAML Values
Property Value
Type: System.Windows.StyleA defined style that is the basis of the current style. The default value is Nothing.
Each style supports only one BasedOn style. The BasedOn style cannot be changed when a Style is sealed. The TargetType property of a BasedOn style must match or be derived from the TargetType of a base style.
A Style is sealed either when the Seal method is called on the Style or when the Style is applied to a FrameworkElement. When a Style is sealed, all the base styles it derives from up the inheritance chain are also sealed.
When a base style and the BasedOn style have the same property, the property value set in the BasedOn style is used.
A style cannot be based on itself, or on any style that derives from it down the inheritance chain.
The following example creates a Style named InheritedStyle that is based on a Style named BaseStyle. InheritedStyle inherits the Background value of Yellow from BaseStyle and adds a Foreground value of Blue.
<StackPanel> <StackPanel.Resources> <Style x:Key="BaseStyle" TargetType="Button"> <Setter Property="Background" Value="Yellow" /> </Style> <!--Create a Style based on BaseStyle--> <Style x:Key="InheritedStyle" TargetType="Button" BasedOn="{StaticResource BaseStyle}"> <Setter Property="Foreground" Value="Red" /> </Style> </StackPanel.Resources> <!--A button with default style--> <Button Content="HelloWorld" /> <!--A button with base style--> <Button Content="HelloWorld" Style="{StaticResource BaseStyle}" /> <!--A button with a style that is inherited from the BaseStyle--> <Button Content="HelloWorld" Style="{StaticResource InheritedStyle}" /> </StackPanel>