BasedOn Property
Collapse the table of content
Expand the table of content

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.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public Style BasedOn { get; set; }
<object BasedOn="styleReference" .../>

XAML Values


A reference to an existing style. Typically, this uses a StaticResource reference to another style defined in resource dictionaries.

Property Value

Type: System.Windows.Style
A defined style that is the basis of the current style. The default value is null.

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.

        <Style x:Key="BaseStyle" TargetType="Button">
            <Setter Property="Background" Value="Yellow" />
        <!--Create a Style based on BaseStyle-->
        <Style x:Key="InheritedStyle" TargetType="Button" BasedOn="{StaticResource BaseStyle}">
            <Setter Property="Foreground" Value="Red" />
    <!--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}" />

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2017 Microsoft