Share via


Custom Rules

A custom rule uses expanded form and allows greater complexity than a convenience rule. For example, you can set up multiple actions and multiple conditions. You can specify how multiple conditions are combined (with AND or OR clauses) by using the ConditionLogicalOp attribute. By default, this value is "And" and all conditions must be met unless you specify otherwise.

Each rule has two parts: a set of conditions and a set of actions.

Possible conditions:

  • Equality evaluates whether the source equals a given value. You can specify other operators in the ConditionOp attribute. The default value is "Equals".
  • IsType evaluates whether the source is a given type.
  • IsValid evaluates whether the source path can be evaluated without error and contains no null values in the path. For example, with a path of "[A.B.C]", IsValid fails if A or B returns null.
  • Modified evaluates whether the source has changed. A source for a Modified condition can be a property value, event, or dictionary.

Possible actions:

  • DebugTrace generates a debugging trace for the rule.
  • Invoke calls a method on any object. Invoke actions support methods with any number of parameters and handle return results. Invoke actions are a useful way to interact with data or code objects when a user interacts with the UI.
  • Navigate navigates to a specified MCML resource destination. Navigate supports http-based navigation targets, and http GET and POST requests.
  • PlayAnimation plays an animation.
  • PlaySound plays a sound.
  • Set defines an action. A target for a Set action can be a property value, a single-parameter method, or dictionaries.

The following example shows a simple rule that tests an equality condition (whether the current view item has mouse focus) and results in an action (sets the target's color):

    <Rule>
        <Conditions>
            <Equality Source="[Input.MouseFocus]" Value="true"/>
        </Conditions>
        <Actions>
            <Set Target="[Label.Color]" Value="[LabelHover]"/>
        </Actions>
    </Rule>

Sample Explorer

  • Rules > all samples
  • Custom Rules > all samples

See Also