Udostępnij za pośrednictwem


<DeviceSpecific> Element

The <DeviceSpecific> element provides a construct for specifying a choice between multiple content alternatives within template sets and within controls that require device-specific choices. Within a <DeviceSpecific> element, you typically specify one or more <Choice> elements, each containing attributes that specify how to evaluate the choice against target device capabilities. At run time, each choice is evaluated in order, and the first choice that is successfully evaluated is used. Each <Choice> element can contain the following:

  • A Filter property that specifies the name of the device filter to evaluate.

  • Additional properties that override properties of the parent control.

  • Template definitions for the control.

The choice element always evaluates to true if the Filter property is omitted. If no other choice is declared before it is picked, the default choice is picked.

Properties

Property

Description

Choices

Returns the collection of choices in a <DeviceSpecific> element.

HasTemplates

Returns true if the currently selected choice of the <DeviceSpecific>/<Choice> construct has templates defined inside it.

MobilePage

Returns the mobile page containing this <DeviceSpecific> element.

Owner

Returns the owner of this <DeviceSpecific> element, either a control or a style.

SelectedChoice

Returns the currently selected choice, or null if none are applicable.

Containment Rules

The following controls can contain a <DeviceSpecific> element.

Control

Comments

MobileControl

A MobileControl control, or any control that inherits from a MobileControl object, can contain zero or one <DeviceSpecific> elements.

Style

A Style control, or any element that inherits from a Style object, can contain zero or one <DeviceSpecific> elements.

A <DeviceSpecific> element can contain the following controls.

Control

Comments

DeviceSpecificChoice

A <DeviceSpecific> element can contain any number of DeviceSpecificChoice controls.

Example

Description

This example uses the PrefersGIF and PrefersWBMP device filters to choose among three image URLs based on device capabilities.

Note

The specified device filters must be available in the Web.config file. For more information, see Mobile Device Capabilities.

Code

<DeviceSpecific>
  <Choice Filter="PrefersGIF" ImageUrl="colorImg.gif"/>
  <Choice Filter="PrefersWBMP" ImageUrl="myImage.wbmp"/>
  <Choice ImageUrl="monoImg.gif"/>
</DeviceSpecific>

See Also

Concepts

Mobile Controls Reference

Reference

<Choice> Element (.NET Framework Developer's Guide )

Other Resources

Element Reference