Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Setting Up Rules

Rules provide priority-based data-binding services that are evaluated at run time. They allow you to evaluate state in markup without having to write code.

Each rule consists of sources and targets, actions and conditions. If a set of conditions evaluates to true for a given source, a set of actions is applied to the target. The source of a condition should not be the same as the target of an action in the same rule.

The following example shows how to change the color of a text string when you mouse over it. Mouse input is the source, text color is the target. When the mouse focus is true, the text color changes.

    <Rules>
      <Condition Source="[Input.MouseFocus]" SourceValue="true" 
                 Target="[Display.Color]" Value="White" />
    </Rules>

    <Content>
      <Text Name="Display" Content="Mouse over this text to change its color." 
            Color="Red" Font="Arial,20" MouseInteractive="true" />
    </Content>

Rules are priority-based in that the first has highest priority; when determining a value for a target, the first applicable rule is applied. To continue to apply other rules, even after the first applicable rule has been applied, set the ExclusiveApply="false" attribute for the Set and Invoke actions. In general, rules are asynchronous; however, conditions are evaluated in the order they are specified.

Rules are shared among user interfaces, so the Source, Target, and Value properties take object paths as values to access objects that have been defined elsewhere in the markup. For more information, see Using Object Paths.

Rules run and get their initial update anytime the UI is created. When navigating away from the page, only the state that was passed in through Properties is retained (Locals are discarded). When returning to the page, the Properties are passed to the UI again, so the UI is recreated and rules run again.

You can use predefined convenience rules, or create custom rules when a convenience rule is not adequate.

TopicDescription
Convenience RulesDescribes the different convenience rules, which are predefined inline rules that are used for common condition-action combinations for one source and one target.
Custom RulesDescribes how to create a complex rule by combining conditions and actions.
Using TransformersDescribes how to use transformer objects to convert values in MCML.
Adding Accessibility SupportProvides resources for adding accessibility support to your applications, describes how to determine which color scheme the user has selected for Windows Media Cente, and describes how to map certain UI functions to standard accessibility actions that can be used by external accessibility aides.

Sample Explorer

  • Rules > all samples
  • MediaCenterEnvironment > Media Collection Mixed

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.