Editare

Partajați prin


Setter Class

Definition

Represents a setter that applies a property value.

public ref class Setter : System::Windows::SetterBase
public ref class Setter : System::Windows::SetterBase, System::ComponentModel::ISupportInitialize
public class Setter : System.Windows.SetterBase
[System.Windows.Markup.XamlSetMarkupExtension("ReceiveMarkupExtension")]
[System.Windows.Markup.XamlSetTypeConverter("ReceiveTypeConverter")]
public class Setter : System.Windows.SetterBase, System.ComponentModel.ISupportInitialize
type Setter = class
    inherit SetterBase
[<System.Windows.Markup.XamlSetMarkupExtension("ReceiveMarkupExtension")>]
[<System.Windows.Markup.XamlSetTypeConverter("ReceiveTypeConverter")>]
type Setter = class
    inherit SetterBase
    interface ISupportInitialize
Public Class Setter
Inherits SetterBase
Public Class Setter
Inherits SetterBase
Implements ISupportInitialize
Inheritance
Attributes
Implements

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>

Remarks

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

You must specify both the Property and Value properties on a Setter for the setter to be meaningful. In .NET 8 and earlier versions, an exception is thrown if one or both properties aren't set.

Content Model: In .NET 9 and later versions, the content property for Setter is Value, and it's optional to specify Value as an attribute.

Constructors

Setter()

Initializes a new instance of the Setter class.

Setter(DependencyProperty, Object)

Initializes a new instance of the Setter class with the specified property and value.

Setter(DependencyProperty, Object, String)

Initializes a new instance of the Setter class with the specified property, value, and target name.

Properties

IsSealed

Gets a value that indicates whether this object is in an immutable state.

(Inherited from SetterBase)
Property

Gets or sets the property to which the Value will be applied.

TargetName

Gets or sets the name of the object this Setter is intended for.

Value

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

Methods

CheckSealed()

Checks whether this object is read-only and cannot be changed.

(Inherited from SetterBase)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ReceiveMarkupExtension(Object, XamlSetMarkupExtensionEventArgs)

Handles cases where a markup extension provides a value for a property of Setter object.

ReceiveTypeConverter(Object, XamlSetTypeConverterEventArgs)

Handles cases where a type converter provides a value for a property of a Setter object.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

ISupportInitialize.BeginInit()

Signals the object that initialization is starting.

ISupportInitialize.EndInit()

Signals the object that initialization is complete.

Applies to

See also