DataTrigger.Value プロパティ

定義

データ オブジェクトのプロパティ値と比較する値を取得または設定します。

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("Binding")]
public object Value { get; set; }
[<System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)>]
[<System.Windows.Markup.DependsOn("Binding")>]
member this.Value : obj with get, set
Public Property Value As Object

プロパティ値

Object

既定値は null です。 「例外」も参照してください。

属性

例外

式はサポートされていません。 バインディングはサポートされていません。

次の例では、ItemsSourceこれらのListBoxオブジェクトは Place オブジェクトの PlacesObservableCollection<T> にバインドされています。 Place オブジェクトにはプロパティ NameState があります

ListBoxItem オブジェクトに ListBox Place オブジェクトが表示されます。 この Style 例では、各 ListBoxItem.

Place DataTrigger データ項目状態 が "WA" の場合、対応するListBoxItem前景が赤に設定されるように指定されます。

<Window.Resources>
  <c:Places x:Key="PlacesData"/>

  <Style TargetType="ListBoxItem">
    <Style.Triggers>
      <DataTrigger Binding="{Binding Path=State}" Value="WA">
        <Setter Property="Foreground" Value="Red" />
      </DataTrigger>	
      <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
          <Condition Binding="{Binding Path=Name}" Value="Portland" />
          <Condition Binding="{Binding Path=State}" Value="OR" />
        </MultiDataTrigger.Conditions>
        <Setter Property="Background" Value="Cyan" />
      </MultiDataTrigger>
    </Style.Triggers>
  </Style>

  <DataTemplate DataType="{x:Type c:Place}">
    <Canvas Width="160" Height="20">
      <TextBlock FontSize="12"
             Width="130" Canvas.Left="0" Text="{Binding Path=Name}"/>
      <TextBlock FontSize="12" Width="30"
                 Canvas.Left="130" Text="{Binding Path=State}"/>
    </Canvas>
  </DataTemplate>
</Window.Resources>

<StackPanel>
  <TextBlock FontSize="18" Margin="5" FontWeight="Bold"
    HorizontalAlignment="Center">Data Trigger Sample</TextBlock>
  <ListBox Width="180" HorizontalAlignment="Center" Background="Honeydew"
    ItemsSource="{Binding Source={StaticResource PlacesData}}"/>
</StackPanel>

次の例では、1 つの で定義されている 2 つの DataTriggers を DataTemplate示します。 このDataTemplateオブジェクトは、SpecialFeatures プロパティを持つ AuctionItem データ オブジェクト (この例では示されていません) に適用されます。 完全な例については、 データ バインディング デモ を参照してください。

1 つ目 DataTrigger は、データ オブジェクトの SpecialFeatures 値が Color の場合、アイテムが海軍のタイトルを持つドジャーブルーの背景で表示されるように指定されます。 データ オブジェクトの SpecialFeatures の値が Highlight の場合、2 番目 DataTrigger のオブジェクトがアクティブになり、項目が星の付いたオレンジ色の境界線で表示されます。

<DataTemplate.Triggers>
    <DataTrigger Binding="{Binding Path=SpecialFeatures}">
        <DataTrigger.Value>
            <src:SpecialFeatures>Color</src:SpecialFeatures>
        </DataTrigger.Value>
      <DataTrigger.Setters>
        <Setter Property="BorderBrush" Value="DodgerBlue" TargetName="border" />
        <Setter Property="Foreground" Value="Navy" TargetName="descriptionTitle" />
        <Setter Property="Foreground" Value="Navy" TargetName="currentPriceTitle" />
        <Setter Property="BorderThickness" Value="3" TargetName="border" />
        <Setter Property="Padding" Value="5" TargetName="border" />
      </DataTrigger.Setters>
    </DataTrigger>
    <DataTrigger Binding="{Binding Path=SpecialFeatures}">
        <DataTrigger.Value>
            <src:SpecialFeatures>Highlight</src:SpecialFeatures>
        </DataTrigger.Value>
        <Setter Property="BorderBrush" Value="Orange" TargetName="border" />
        <Setter Property="Foreground" Value="Navy" TargetName="descriptionTitle" />
        <Setter Property="Foreground" Value="Navy" TargetName="currentPriceTitle" />
        <Setter Property="Visibility" Value="Visible" TargetName="star" />
        <Setter Property="BorderThickness" Value="3" TargetName="border" />
        <Setter Property="Padding" Value="5" TargetName="border" />
    </DataTrigger>
</DataTemplate.Triggers>

注釈

XAML プロパティ要素の使用

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

この値は、. のプロパティによって Binding 生成されるプロパティ DataTrigger値と比較されます。 この比較は参照の等価性チェックです。 2 つの値が等しい場合は、関連付けられたアクションまたはセッターが適用されます。

データ トリガーが意味を持つには、a DataTriggerBindingプロパティとValueプロパティの両方を指定する必要があることに注意してください。 一方または両方のプロパティが設定されていない場合は、例外がスローされます。

適用対象

こちらもご覧ください