Setter 类
定义
表示应用属性值的 setter。Represents a setter that applies a property value.
public ref class Setter : System::Windows::SetterBase, System::ComponentModel::ISupportInitialize
[System.Windows.Markup.XamlSetMarkupExtension("ReceiveMarkupExtension")]
[System.Windows.Markup.XamlSetTypeConverter("ReceiveTypeConverter")]
public class Setter : System.Windows.SetterBase, System.ComponentModel.ISupportInitialize
type Setter = class
inherit SetterBase
interface ISupportInitialize
Public Class Setter
Inherits SetterBase
Implements ISupportInitialize
- 继承
- 属性
- 实现
示例
下面的示例定义了将应用于每个 TextBlock 元素的 Style。The following example defines a Style that will be applied to every TextBlock element. 此 Style 将值应用于 Setter的多个 TextBlock 属性。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>
下面的示例演示可用于 Button 控件的命名 Style。The following example shows a named Style available to Button controls. Style 定义一个 Trigger 元素,该元素在 IsPressed 属性 true
时更改按钮的 Foreground 属性。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>
注解
Style和不同类型的触发器(继承自 TriggerBase的类)使用 Setter来应用属性值。Styles and the different types of triggers (classes that inherit from TriggerBase) use Setters to apply property values.
请注意,必须在 Setter 上同时指定 Property 和 Value 属性,这样 setter 才有意义。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.
构造函数
Setter() |
初始化 Setter 类的新实例。Initializes a new instance of the Setter class. |
Setter(DependencyProperty, Object) |
用指定的属性和值初始化 Setter 类的新实例。Initializes a new instance of the Setter class with the specified property and value. |
Setter(DependencyProperty, Object, String) |
用指定的属性、值和目标名称初始化 Setter 类的新实例。Initializes a new instance of the Setter class with the specified property, value, and target name. |
属性
IsSealed |
获取一个值,该值指示此对象是否处于不可变状态。Gets a value that indicates whether this object is in an immutable state. (继承自 SetterBase) |
Property |
获取或设置要应用 Value 的属性。Gets or sets the property to which the Value will be applied. |
TargetName |
获取或设置此 Setter 所用于的对象的名称。Gets or sets the name of the object this Setter is intended for. |
Value |
获取或设置要应用于此 Setter 所指定的属性的值。Gets or sets the value to apply to the property that is specified by this Setter. |
方法
CheckSealed() |
检查此对象是否为只读且无法更改。Checks whether this object is read-only and cannot be changed. (继承自 SetterBase) |
Equals(Object) |
确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
GetHashCode() |
用作默认哈希函数。Serves as the default hash function. (继承自 Object) |
GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
ReceiveMarkupExtension(Object, XamlSetMarkupExtensionEventArgs) |
处理标记扩展为 Setter 对象的属性提供值的情况。Handles cases where a markup extension provides a value for a property of Setter object. |
ReceiveTypeConverter(Object, XamlSetTypeConverterEventArgs) |
处理类型转换器为 Setter 对象的属性提供值的情况。Handles cases where a type converter provides a value for a property of a Setter object. |
ToString() |
返回一个表示当前对象的 string。Returns a string that represents the current object. (继承自 Object) |
显式界面实现
ISupportInitialize.BeginInit() |
用信号通知对象初始化即将开始。Signals the object that initialization is starting. |
ISupportInitialize.EndInit() |
用信号通知对象初始化已完成。Signals the object that initialization is complete. |