Skip to main content
.NET Framework Class Library
Setter Class

Represents a setter that applies a property value.

Namespace:   System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Syntax
<[%$TOPIC/ms589786_en-us_VS_110_2_0_0_0_0%]("ReceiveTypeConverter")> _
<[%$TOPIC/ms589786_en-us_VS_110_2_0_0_0_1%]("ReceiveMarkupExtension")> _
Public Class Setter _
	Inherits [%$TOPIC/ms589786_en-us_VS_110_2_0_0_0_2%] _
	Implements [%$TOPIC/ms589786_en-us_VS_110_2_0_0_0_3%]
[[%$TOPIC/ms589786_en-us_VS_110_2_0_1_0_0%]("ReceiveTypeConverter")]
[[%$TOPIC/ms589786_en-us_VS_110_2_0_1_0_1%]("ReceiveMarkupExtension")]
public class Setter : [%$TOPIC/ms589786_en-us_VS_110_2_0_1_0_2%], [%$TOPIC/ms589786_en-us_VS_110_2_0_1_0_3%]
[[%$TOPIC/ms589786_en-us_VS_110_2_0_2_0_0%](L"ReceiveTypeConverter")]
[[%$TOPIC/ms589786_en-us_VS_110_2_0_2_0_1%](L"ReceiveMarkupExtension")]
public ref class Setter : public [%$TOPIC/ms589786_en-us_VS_110_2_0_2_0_2%], 
	[%$TOPIC/ms589786_en-us_VS_110_2_0_2_0_3%]
[<[%$TOPIC/ms589786_en-us_VS_110_2_0_3_0_0%]("ReceiveTypeConverter")>]
[<[%$TOPIC/ms589786_en-us_VS_110_2_0_3_0_1%]("ReceiveMarkupExtension")>]
type Setter =  
    class 
        inherit [%$TOPIC/ms589786_en-us_VS_110_2_0_3_0_2%] 
        interface [%$TOPIC/ms589786_en-us_VS_110_2_0_3_0_3%] 
    end
<Setter .../>

The Setter type exposes the following members.

Constructors
  NameDescription
Public method SetterInitializes a new instance of the Setter class.
Public method Setter(DependencyProperty, Object)Initializes a new instance of the Setter class with the specified property and value.
Public method Setter(DependencyProperty, Object, String)Initializes a new instance of the Setter class with the specified property, value, and target name.
Top
Properties
  NameDescription
Public property IsSealedGets a value that indicates whether this object is in an immutable state. (Inherited from SetterBase.)
Public property PropertyGets or sets the property to which the Value will be applied.
Public property TargetNameGets or sets the name of the object this Setter is intended for.
Public property ValueGets or sets the value to apply to the property that is specified by this Setter.
Top
Methods
  NameDescription
Protected method CheckSealedChecks whether this object is read-only and cannot be changed. (Inherited from SetterBase.)
Public method Equals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected method FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCodeServes as the default hash function. (Inherited from Object.)
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public method Static member ReceiveMarkupExtensionHandles cases where a markup extension provides a value for a property of Setter object.
Public method Static member ReceiveTypeConverterHandles cases where a type converter provides a value for a property of a Setter object.
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implemetation Private method ISupportInitializeBeginInitInfrastructure. Signals the object that initialization is starting.
Explicit interface implemetation Private method ISupportInitializeEndInitInfrastructure. Signals the object that initialization is complete.
Top
Exceptions
ExceptionCondition
ArgumentNullException

The Property property cannot be null.

ArgumentException

If the specified Property is a read-only property.

ArgumentException

If the specified Value is set to UnsetValue.

Remarks

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.

Examples

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" />
</Style>

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">
    <Style.Triggers>
    <Trigger Property="IsPressed" Value="true">
        <Setter Property = "Foreground" Value="Green"/>
    </Trigger>
    </Style.Triggers>
</Style>
Version Information

.NET Framework

Supported in: 4.5.3, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

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