Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 4
System.Windows
Setter Class
Setter Properties
 Value Property
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2010/.NET Framework 4

Other versions are also available for the following:
.NET Framework Class Library
Setter..::.Value Property

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

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Visual Basic
<LocalizabilityAttribute(LocalizationCategory.None, Readability := Readability.Unreadable)> _
<TypeConverterAttribute(GetType(SetterTriggerConditionValueConverter))> _
Public Property Value As Object
    Get
    Set
C#
[LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable)]
[TypeConverterAttribute(typeof(SetterTriggerConditionValueConverter))]
public Object Value { get; set; }
Visual C++
[LocalizabilityAttribute(LocalizationCategory::None, Readability = Readability::Unreadable)]
[TypeConverterAttribute(typeof(SetterTriggerConditionValueConverter))]
public:
property Object^ Value {
    Object^ get ();
    void set (Object^ value);
}
F#
[<LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable)>]
[<TypeConverterAttribute(typeof(SetterTriggerConditionValueConverter))>]
member Value : Object with get, set
XAML Property Element Usage
<object>
  <object.Value>
    value
  </object.Value>
</object>
XAML Attribute Usage
<object Value="value"/>

XAML Values

value

An object or a markup extension. See StaticResource Markup Extension.

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

Data binding and dynamic resources within the object is supported if the specified value is a Freezable object. See Binding Markup Extension and DynamicResource Markup Extension.

Property Value

Type: System..::.Object
The default value is UnsetValue.
ExceptionCondition
ArgumentException

If the specified Value is set to UnsetValue.

The following example defines a Style that will be applied to every TextBlock element. For the complete example, see Introduction to Styling and Templating Sample.

XAML
<Style TargetType="{x:Type TextBlock}">
  <Setter Property="FontFamily" Value="Segoe Black" />
  <Setter Property="HorizontalAlignment" Value="Center" />
  <Setter Property="FontSize" Value="12pt" />
  <Setter Property="Foreground" Value="#777777" />
</Style>

The following example defines a Style with Setters that reference system resources.

XAML
<Style x:Key="SystemResStyle" TargetType="{x:Type Button}">
    <Setter Property = "Background" Value= 
                       "{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}"/>
    <Setter Property = "Foreground" Value= 
                       "{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"/>
    <Setter Property = "FontSize" Value= 
                       "{DynamicResource {x:Static SystemFonts.IconFontSizeKey}}"/>
    <Setter Property = "FontWeight" Value= 
                       "{DynamicResource {x:Static SystemFonts.MessageFontWeightKey}}"/>
    <Setter Property = "FontFamily" Value= 
                       "{DynamicResource {x:Static SystemFonts.CaptionFontFamilyKey}}"/>
</Style>

The following example defines a Style for the RepeatButton.

XAML
        <Style x:Key="Slider_Thumb" TargetType="{x:Type Thumb}">
            <Setter Property="OverridesDefaultStyle" Value="true" />
            <Setter Property="Width" Value="14" />
            <Setter Property="Height" Value="14" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Thumb}">
                        <Grid Width="14" Height="14">
                            <Ellipse Fill="{TemplateBinding Foreground}" />
                            <Ellipse Stroke="{TemplateBinding BorderBrush}" StrokeThickness="1" x:Name="ThumbCover" >
                                <Ellipse.Fill>
                                    <LinearGradientBrush  EndPoint="0,1" StartPoint="0,0">
                                        <LinearGradientBrush.GradientStops>
                                            <GradientStop Color="#CCFFFFFF" Offset="0" />
                                            <GradientStop Color="#00000000" Offset=".5" />
                                            <GradientStop Color="#66000000" Offset="1" />
                                        </LinearGradientBrush.GradientStops>
                                    </LinearGradientBrush>
                                </Ellipse.Fill>
                            </Ellipse>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsDragging" Value="true">
                                <Setter TargetName="ThumbCover" Property="Fill">
                                    <Setter.Value>
                                        <LinearGradientBrush  EndPoint="0,1" StartPoint="0,0">
                                            <LinearGradientBrush.GradientStops>
                                                <GradientStop Color="#CCFFFFFF" Offset="1" />
                                                <GradientStop Color="#00000000" Offset=".5" />
                                                <GradientStop Color="#66000000" Offset="0" />
                                            </LinearGradientBrush.GradientStops>
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

The following example shows a Value property that uses the Binding declaration. For the complete example, see Binding Validation Sample.

XAML
<Style x:Key="textBoxInError" TargetType="{x:Type TextBox}">
  <Style.Triggers>
    <Trigger Property="Validation.HasError" Value="true">
      <Setter Property="ToolTip"
        Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                        Path=(Validation.Errors)[0].ErrorContent}"/>
    </Trigger>
  </Style.Triggers>
</Style>

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker