Windows Dev Center

Setter.Value Property

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

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public Object Value { get; set; }
<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.

  • Whether to use attribute syntax or property element syntax depends both on the property type of the property being set, as well as whether you choose to use extension mechanisms such as referencing existing resources. For example, property element syntax might be required if you want the style to define a new ImageBrush as the value for a property that takes a Brush property type, but attribute syntax could be used if you chose a SolidColorBrush instead, or referenced an existing ImageBrush with a StaticResource usage.

  • Generally, objectValue is a single object element, but multiple object elements are technically possible in the usage if you are setting a dependency property that takes an implicit collection type.

Property Value

Type: System.Object
The value to apply to the property that is specified by the Setter.

Note that you must specify both the Property and Value properties on a Setter or an exception is thrown.

You cannot change this property if IsSealed is true.

The following 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 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>


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2015 Microsoft