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
[LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable)] [TypeConverterAttribute(typeof(SetterTriggerConditionValueConverter))] public Object Value { get; set; }
<object> <object.Value> value </object.Value> </object>
<object Value="value"/>
XAML Values
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.
| Exception | Condition |
|---|---|
| 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.
<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.
<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.
<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.
<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>
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.