Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Setter Class
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Setter Class

Updated: November 2007

Represents a setter that applies a property value.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/xaml/presentation

Visual Basic (Declaration)
Public Class Setter _
    Inherits SetterBase
Visual Basic (Usage)
Dim instance As Setter
C#
public class Setter : SetterBase
Visual C++
public ref class Setter : public SetterBase
J#
public class Setter extends SetterBase
JScript
public class Setter extends SetterBase
XAML Object Element Usage
<Setter .../>
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.

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.

C#
<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.

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

System..::.Object
  System.Windows..::.SetterBase
    System.Windows..::.Setter
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows Vista

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

.NET Framework

Supported in: 3.5, 3.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker