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)

public:
[DependsOnAttribute("Property")]
[DependsOnAttribute("TargetName")]
[LocalizabilityAttribute(LocalizationCategory::None, Readability = Readability::Unreadable)]
[TypeConverterAttribute((SetterTriggerConditionValueConverter^::typeid))]
property Object^ Value {
	Object^ get();
	void set(Object^ value);
}

Property Value

Type: System::Object^

The default value is UnsetValue.

Exception Condition
ArgumentException

If the specified Value is set to UnsetValue.

<object Value="value"/>

<object>
  <object.Value>
    value
  </object.Value>
</object>

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.

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>

.NET Framework
Available since 3.0
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show: