Style.Setters Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets a collection of Setter objects.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
<Style ...> oneOrMoreSetters </Style>
<Style> <Style.Setters> oneOrMoreSetters </Style.Setters> </Style>
XAML Values
The verbose syntax for property element syntax is not necessary because Setters is the content property for Style, and therefore the Style.Setters property element may be omitted. However, some users (and some tools) choose to use an explicit property element usage for Style.Setters.
Property Value
Type: System.Windows.SetterBaseCollectionA collection of Setter objects. The default is an empty collection.
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>