Life’s Passion

My Projects in Eclipse

XWT - Data Trigger (2)

In the previous post, I have shown up the Trigger, which is in fact a Control Trigger. The source of Trigger is a UI Control such as Button. It looks like Control Binding, but it is a little bit different in features. Control binding is used to synchronize the state of the two controls. It is always bidirectinal and one to one property synchronization. Trigger is one direction from source to target, and it supports the property binding of 1 to N, N to 1 and also N to N .

This post will deal with Data Trigger. The source of Trigger is data context of UI control instead of UI Control it-self. Like Trigger, Data Trigger has also two implementation classes, one for the simple case and another for the complexe one:

DataTrigger

A DataTrigger allows you to set property values when a property value of the data object matches a specified Value. For example, if you are displaying a list of Employee objects, you may want the foreground color of the name to be different based on each Employee’s current attendance: employees who are currently on vacation are displayed with a purple foreground.

<Label>
  <Label.triggers>
    <DataTrigger binding="{Binding path=attendance}" value="inVacation" >
      <Setter property="foreground" value="Purple"/>	 </DataTrigger>
  </Label.triggers>
</Label>

MultiDataTrigger

A MultiDataTrigger object is similar to a MultiTrigger, except the conditions of a MultiDataTrigger are based on property values of bound data instead of those of a UI Control. In a MultiDataTrigger, a condition is met when the property value of the data item matches the specified Value. You can then use setters to apply changes when all conditions are met.

Using the same example above, we can add a new condition like location is in France.

<Label>
  <Label.triggers>
     <MultiDataTrigger>
        <MultiDataTrigger.conditions>
          <Condition binding="{Binding path=attendance}" value="inVacation"/>
          <Condition binding="{Binding path=location}" value="France" />
        </MultiDataTrigger.conditions>
        <Setter property="foreground" value="Purple"/>
     </MultiDataTrigger>
  </Label.triggers>
</Label>

Another trigger we have not talked about is EventTrigger. The source of EventTrigger is an event of UI Control. This trigger is mainly used with graphic animation. It will be supported later.

Posted November 1st, 2009 by Yves YANG in category: Declarative UI, XWT
You can skip to the end and leave a response. Pinging is currently not allowed.

Leave a Reply

You must be logged in using your Eclipse Bugzilla account to post a comment.

Recent Posts

Archives

Categories

Meta