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 です。

属性

例外

指定した ValueUnsetValue が設定されている場合。

次の例では、 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>

次の例では、 の RepeatButtonStyle定義します。

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

次の例は、 宣言を Value 使用するプロパティを Binding 示しています。 完全な例については、「 バインド検証サンプル」を参照してください。

<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 マークアップ拡張機能」を参照してください。

または 例外の プロパティと Value プロパティSetterProperty両方を指定する必要があることに注意してください。

指定した値が オブジェクトの場合、オブジェクト内のデータ バインディングと動的リソースが Freezable サポートされます。 「Binding Markup Extension」と「DynamicResource Markup Extension」を参照してください。

適用対象

こちらもご覧ください