Επεξεργασία

Κοινή χρήση μέσω


Condition.Binding Property

Definition

Gets or sets the binding that specifies the property of the condition. This is only applicable to MultiDataTrigger objects.

public:
 property System::Windows::Data::BindingBase ^ Binding { System::Windows::Data::BindingBase ^ get(); void set(System::Windows::Data::BindingBase ^ value); };
public System.Windows.Data.BindingBase Binding { get; set; }
member this.Binding : System.Windows.Data.BindingBase with get, set
Public Property Binding As BindingBase

Property Value

The default value is null.

Examples

In the following example, the ItemsSource of the ListBox is bound to Places, an ObservableCollection<T> of Place objects. Place objects have properties Name and State.

Each ListBoxItem of the ListBox displays a Place object. The Style in the example is applied to each ListBoxItem. The Conditions of the MultiDataTrigger are specified such that if the Name and State of the Place data item is "Portland" and "OR" respectively, then the background of corresponding ListBoxItem is set to Cyan.

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

Remarks

MultiDataTriggers allow you to set property values based on values of the data that is returned. For example, if you are displaying a list of task items, you may want to display a task with a red background if it is of high priority and has not been looked at for more than two weeks.

You create a binding and use the Path property to bind to a property of a certain object (the binding source object). For example, you may bind to the Priority property of a Task. For more information, see Data Binding Overview.

Note that if it is a condition for a MultiDataTrigger, the Binding and Value properties must be set. Setting the Property value would cause an exception in that case.

XAML Attribute Usage

<object property="{Binding  declaration}"/>  

XAML Property Element Usage

<object>  
  <object.Binding>  
    <Binding …/>  
  </object.Binding>  
</object>  

XAML Values

declaration
A binding declaration. See Binding Declarations Overview for more information.

Applies to

See also