Setter Class
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Applies a value to a property in a Style.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
The Setter type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | 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. |
| Name | Description | |
|---|---|---|
![]() | Dispatcher | Gets the Dispatcher this object is associated with. (Inherited from DependencyObject.) |
![]() | IsSealed | Gets a value that indicates whether this object is in an immutable state. (Inherited from SetterBase.) |
![]() | Property | Gets or sets the property to apply the Value to. |
![]() | Value | Gets or sets the value to apply to the property that is specified by the Setter. |
| Name | Description | |
|---|---|---|
![]() | CheckAccess | Determines whether the calling thread has access to this object. (Inherited from DependencyObject.) |
![]() | ClearValue | Clears the local value of a dependency property. (Inherited from DependencyObject.) |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetAnimationBaseValue | Returns any base value established for a Windows Phone dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | GetValue | Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ReadLocalValue | Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject.) |
![]() | SetValue | Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
A Style contains a collection of one or more Setter objects. Each Setter has a Property and a Value. The Property is the property of the element the style is applied to. The Value is the value that is applied to the property.
You must specify both the Property and Value properties on a Setter or an exception is thrown.
The following example creates two styles: one for a TextBlock and one for a TextBox. The style for the TextBlock sets the Foreground, FontSize, and VerticalAlignment properties. The style for the TextBox sets the Width, Height, Margin, Background, and FontSize properties. Each style is applied to two instances of a control to create a uniform appearance for each TextBlock and TextBox.
<StackPanel> <StackPanel.Resources> <!--Create a Style for a TextBlock that uses some values from the Theme Resources for Windows Phone (http://msdn.microsoft.com/en-us/library/ff769552(v=VS.92).aspx).--> <Style TargetType="TextBlock" x:Key="TextBlockStyle"> <Setter Property="Foreground" Value="{StaticResource PhoneSubtleColor}"/> <Setter Property="Margin" Value="{StaticResource PhoneMargin}"/> <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}"/> <Setter Property="VerticalAlignment" Value="Center"/> </Style> <!--Create a Style for a TextBox that uses some values from the Theme Resources for Windows Phone (http://msdn.microsoft.com/en-us/library/ff769552(v=VS.92).aspx).--> <Style TargetType="TextBox" x:Key="TextBoxStyle"> <Setter Property="Width" Value="300"/> <Setter Property="Height" Value="70"/> <Setter Property="Margin" Value="{StaticResource PhoneMargin}"/> <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}"/> <Setter Property="Background" Value="{StaticResource PhoneAccentColor}" /> </Style> </StackPanel.Resources> <!--Apply the TextBlockStyle and TextBoxStyle to each TextBlock and TextBox, respectively.--> <StackPanel Orientation="Horizontal"> <TextBlock Style="{StaticResource TextBlockStyle}"> First Name: </TextBlock> <TextBox Style="{StaticResource TextBoxStyle}"/> </StackPanel> <StackPanel Orientation="Horizontal"> <TextBlock Style="{StaticResource TextBlockStyle}"> Last Name: </TextBlock> <TextBox Style="{StaticResource TextBoxStyle}" /> </StackPanel> </StackPanel>


