This documentation is archived and is not being maintained.

Setter Class

Represents a setter that applies a property value.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)

type Setter =  
        inherit SetterBase
        interface ISupportInitialize

The Setter type exposes the following members.

Public methodSetter()Initializes a new instance of the Setter class.
Public methodSetter(DependencyProperty, Object)Initializes a new instance of the Setter class with the specified property and value.
Public methodSetter(DependencyProperty, Object, String)Initializes a new instance of the Setter class with the specified property, value, and target name.

Public propertyIsSealedGets a value that indicates whether this object is in an immutable state. (Inherited from SetterBase.)
Public propertyPropertyGets or sets the property to which the Value will be applied.
Public propertyTargetNameGets or sets the name of the object this Setter is intended for.
Public propertyValueGets or sets the value to apply to the property that is specified by this Setter.

Protected methodCheckSealedChecks whether this object is read-only and cannot be changed. (Inherited from SetterBase.)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodStatic memberReceiveMarkupExtensionHandles cases where a markup extension provides a value for a property of Setter object.
Public methodStatic memberReceiveTypeConverterHandles cases where a type converter provides a value for a property of a Setter object.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

Explicit interface implemetationPrivate methodISupportInitialize.BeginInitInfrastructure. Signals the object that initialization is starting.
Explicit interface implemetationPrivate methodISupportInitialize.EndInitInfrastructure. Signals the object that initialization is complete.


The Property property cannot be null.


If the specified Property is a read-only property.


If the specified Value is set to UnsetValue.

Styles and the different types of triggers (classes that inherit from TriggerBase) use Setters to apply property values.

Note that you must specify both the Property and Value properties on a Setter for the setter to be meaningful. If one or both properties are not set, an exception will be thrown.

The following example defines a Style that will be applied to every TextBlock element. This Style applies values to several TextBlock properties with the use of Setters.

<Style TargetType="{x:Type TextBlock}">
  <Setter Property="FontFamily" Value="Segoe Black" />
  <Setter Property="HorizontalAlignment" Value="Center" />
  <Setter Property="FontSize" Value="12pt" />
  <Setter Property="Foreground" Value="#777777" />

The following example shows a named Style available to Button controls. The Style defines a Trigger element that changes the Foreground property of a button when the IsPressed property is true.

<Style x:Key="Triggers" TargetType="Button">
    <Trigger Property="IsPressed" Value="true">
        <Setter Property = "Foreground" Value="Green"/>

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.