Export (0) Print
Expand All

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)

public Object Value { get; set; }
<Setter ...>
<Setter Value="attributeValue"/>
<Setter Value="extensionUsage"/>

XAML Values


An object element that specifies the value of the property being set.


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.


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.

    <!--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"/>

    <!--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">
          <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"/>

  <!--Apply the TextBlockStyle and TextBoxStyle to each 
          TextBlock and TextBox, respectively.-->
  <StackPanel Orientation="Horizontal">
    <TextBlock Style="{StaticResource TextBlockStyle}">
              First Name:
    <TextBox Style="{StaticResource TextBoxStyle}"/>
  <StackPanel Orientation="Horizontal">
    <TextBlock Style="{StaticResource TextBlockStyle}">
              Last Name:
    <TextBox Style="{StaticResource TextBoxStyle}"  

Data Bound Style Values

The following Silverlight 5 example creates an implicit TextBlock style that assigns a binding markup expression to a Setter.Value property. The binding retrieves its value from a property of the current DataContext, which in this case is a simple UserSettings object. In this way, the TextBlock in the example is automatically displayed with the user's preferred FontSize setting. A TextBox bound to the same source enables users to modify the setting and see the change applied immediately.

<UserControl x:Class="SL5DataBindingFeatures.StyleTestPage"

  <StackPanel x:Name="LayoutRoot">

      <Style TargetType="TextBlock">
        <Setter Property="FontSize" Value="{Binding FontSize}"/>

    <TextBlock Text="FontSize"/>
    <TextBox Text="{Binding FontSize, Mode=TwoWay}"



using System;
using System.ComponentModel;
using System.Windows.Controls;

public partial class StyleTestPage : UserControl
    public StyleTestPage()
        DataContext = new UserSettings() { FontSize = 35 };

    private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        // Update the data source whenever the text box value changes.
        (sender as TextBox)

public class UserSettings : INotifyPropertyChanged
    private Double _fontSize;
    public Double FontSize 
        get { return _fontSize; }
            _fontSize = value;
            PropertyChanged(this, new PropertyChangedEventArgs("FontSize"));   
    // Initialize to an empty delegate so that PropertyChanged is never null.
    public event PropertyChangedEventHandler PropertyChanged = delegate { };


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

© 2014 Microsoft