Setter.Value 属性

定义

获取或设置要应用于此 Setter 所指定的属性的值。

public:
 property System::Object ^ Value { System::Object ^ get(); void set(System::Object ^ value); };
[System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)]
[System.Windows.Markup.DependsOn("Property")]
[System.Windows.Markup.DependsOn("TargetName")]
public object Value { get; set; }
[System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)]
[System.Windows.Markup.DependsOn("Property")]
[System.Windows.Markup.DependsOn("TargetName")]
[System.ComponentModel.TypeConverter(typeof(System.Windows.Markup.SetterTriggerConditionValueConverter))]
public object Value { get; set; }
[<System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)>]
[<System.Windows.Markup.DependsOn("Property")>]
[<System.Windows.Markup.DependsOn("TargetName")>]
member this.Value : obj with get, set
[<System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)>]
[<System.Windows.Markup.DependsOn("Property")>]
[<System.Windows.Markup.DependsOn("TargetName")>]
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Markup.SetterTriggerConditionValueConverter))>]
member this.Value : obj with get, set
Public Property Value As Object

属性值

默认值为 UnsetValue

属性

例外

在指定的 Value 设置为 UnsetValue 时引发。

示例

以下示例定义 Style 将应用于每个元素的 TextBlock 。 有关完整示例,请参阅 样式设置和模板化示例简介

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

以下示例定义一个 Style ,其中引用 Setter了系统资源。

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

以下示例为 RepeatButton定义 Style

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

以下示例演示使用 ValueBinding 声明的属性。 有关完整示例,请参阅 绑定验证示例

<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)/ErrorContent}"/>
    </Trigger>
  </Style.Triggers>
</Style>

注解

XAML 属性用法

<object Value="value"/>  

XAML 属性元素用法

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

XAML 值

value
对象或标记扩展。 请参阅 StaticResource 标记扩展

请注意,必须同时PropertyValue指定 和 属性,Setter否则将引发异常。

如果指定的值为 Freezable 对象,则支持对象中的数据绑定和动态资源。 请参阅 绑定标记扩展DynamicResource 标记扩展

适用于

另请参阅