Setter class
Collapse the table of content
Expand the table of content

Setter class

Applies a value to a property in a Style or a VisualState.




public sealed class Setter : SetterBase


The Setter class has these types of members:


The Setter class has these constructors.

Setter Initializes a new instance of the Setter class with no initial Property or Value.
Setter(DependencyProperty,Object) Initializes a new instance of the Setter class with initial Property and Value information.



The Setter class has these methods. It also inherits methods from the Object class.

ClearValue Clears the local value of a dependency property. (Inherited from DependencyObject)
GetAnimationBaseValue Returns any base value established for a dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject)
GetValue Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject)
ReadLocalValue Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject)
RegisterPropertyChangedCallback Registers a notification function for listening to changes to a specific DependencyProperty on this DependencyObject instance. (Inherited from DependencyObject)
SetValue Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject)
UnregisterPropertyChangedCallback Cancels a change notification that was previously registered by calling RegisterPropertyChangedCallback. (Inherited from DependencyObject)



The Setter class has these properties.

PropertyAccess typeDescription



Gets the CoreDispatcher that this object is associated with. The CoreDispatcher represents a facility that can access the DependencyObject on the UI thread even if the code is initiated by a non-UI thread. (Inherited from DependencyObject)



Gets a value that indicates whether this object is in an immutable state. (Inherited from SetterBase)



Gets or sets the property to apply the Value to.



Gets or sets the path of a property on a target element to apply the Value to.



Gets or sets the value to apply to the property that is specified by the Setter.



Use Setter statements to set a property value within a Style or a VisualState.

The Setter.Target property can be used in either a Style or a VisualState, but in different ways. When used in a Style, the property that needs to be modified can be specified directly. When used in VisualState, the Target property must be given a TargetPropertyPath (dotted syntax with a target element and property explicitly specified).

The Setter.Property property can be used only in a Style and not in a VisualState. Starting in Windows 10, you can use Setter.Target everywhere instead of Setter.Property.

You must specify both the Value, and the Target or Property, on a Setter. Otherwise, an exception is thrown (either a parse exception or runtime error, depending on whether the Setter is created in XAML or modified in code).

If you're accessing a Setter instance using code, you cannot change the value of any property of a Setter instance if the value of the IsSealed property on a parent Style is true. This is also reported by the IsSealed property on an individual Setter. The system sets these properties to true when the runtime applies styles to UI elements and displays them in the UI. Attempting to change a sealed Setter throws a runtime error.

Migration notes

  • Windows Presentation Foundation (WPF) and Microsoft Silverlight supported the ability to use a Binding expression to supply the Value for a Setter in a Style. The Windows Runtime doesn't support a Binding usage for Setter.Value (the Binding won't evaluate and the Setter has no effect, you won't get errors, but you won't get the desired result either). When you convert XAML styles from WPF or Silverlight XAML, replace any Binding expression usages with strings or objects that set values, or refactor the values as shared {StaticResource} markup extension values rather than Binding-obtained values.


This example shows how to use Setter statements in a style for TextBlock elements.

        <!-- Create a Style for a TextBlock to specify that the
             Foreground equals Navy, FontSize equals 14, and
             VerticalAlignment equals Bottom. -->
        <Style TargetType="TextBlock" x:Key="TextBlockStyle">
            <Setter Property="Foreground" Value="Navy"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="VerticalAlignment" Value="Bottom"/>
    <!-- Apply the TextBlockStyle to 2 different TextBlocks. -->
    <TextBlock Style="{StaticResource TextBlockStyle}" Text=”Hello”/>
    <TextBlock Style="{StaticResource TextBlockStyle}" Text=”World”/>

This example shows how to use multiple Setter statements inside the VisualState.Setters property to apply discrete property value changes on various elements (without animations) when a VisualState is applied.

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
                <VisualState x:Name="NarrowState">
                        <Setter Target="myPanel.Orientation" Value="Vertical"/>
                        <Setter Target="myPanel.Width" Value="380"/>
                        <Setter Target="myTextBlock.MaxLines" Value="3"/>
        <StackPanel x:Name="myPanel" Orientation="Horizontal">
            <TextBlock x:Name="myTextBlock" MaxLines="5" Style="{ThemeResource BodyTextBlockStyle}"/>

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


Windows::UI::Xaml [C++]



Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]


Windows::UI::Xaml [C++]





See also

Migrating Silverlight or WPF XAML/code to a Windows Store app



© 2016 Microsoft