Setter.Value property
Gets or sets the value to apply to the property that is specified by the Setter.
Syntax
<Setter ...> <Setter.Value> objectValue </Setter.Value> </Setter>
<Setter Value="attributeValue"/> -or- <Setter Value="extensionUsage"/>
XAML Values
- objectValue
-
An object element that specifies the value of the property being set.
- attributeValue
-
A string that specifies the attribute value of the property being set. The format and interpretation of the string provided for the attribute value depends on the property being set.
- extensionUsage
-
One of several possible extension mechanisms that specify the property value to be obtained from an existing value. The most common of these is StaticResource.
Property value
Type: System.Object [.NET] | Platform::Object [C++]
The value to apply to the property that is specified by the Setter.
Examples
This example creates two styles: one for a TextBlock and one for a TextBox. Each style is applied to two instances of a control to create a uniform appearance for each TextBlock and 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. Notice that the setter for the Background of the TextBox uses the property element syntax for the value so that the Background can use a LinearGradientBrush.
<StackPanel> <StackPanel.Resources> <!--Create a Style for a TextBlock to specify that the Foreground equals Navy, FontSize equals 14, and VerticalAlignment equals Botton.--> <Style TargetType="TextBlock" x:Key="TextBlockStyle"> <Setter Property="Foreground" Value="Navy"/> <Setter Property="FontSize" Value="14"/> <Setter Property="VerticalAlignment" Value="Bottom"/> </Style> <!--Create a Style for a TextBlock that specifies that the Width is 200, Height is 20, Margin is 4, Background is LightBlue, and FontSize is 14.--> <Style TargetType="TextBox" x:Key="TextBoxStyle"> <Setter Property="Width" Value="200"/> <Setter Property="Height" Value="30"/> <Setter Property="Margin" Value="4"/> <Setter Property="FontSize" Value="14"/> <Setter Property="Background"> <Setter.Value> <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5"> <GradientStop Color="White" Offset="0.0"/> <GradientStop Color="LightBlue" Offset="0.5"/> <GradientStop Color="Navy" Offset="1"/> </LinearGradientBrush> </Setter.Value> </Setter> </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}" Margin="6,4,4,4"/> </StackPanel> </StackPanel>
Requirements
|
Minimum supported client | Windows 8 |
|---|---|
|
Minimum supported server | Windows Server 2012 |
|
Namespace |
|
|
Metadata |
|
See also
Build date: 1/31/2013
