Accessing Style Properties in Device Adapters
All ASP.NET mobile controls support style properties for rendering, such as font, color, and alignment. Style properties are handled differently for each mobile device, so each adapter has a different implementation for style rendering.
Additionally, all mobile controls have an associated style object that contains style properties directly defined for the control. The style object must be an instance of a class that inherits from System.Web.UI.MobileControls.Style.
The style object is defined as a protected field of the MobileControl base class, and is thus hidden from the page developer. However, for each property of a Style object, the associated control class also exposes a public property that you, as a page developer, can access by reading or writing to it. For example, the MobileControl base class exposes all of the properties of the Style base class as its own.
In addition, styles follow an inheritance model. At rendering time, control adapters can retrieve style information that includes inherited values by using a special indexer on the style.
Accessing Style Properties in Control Adapters
To use style properties in rendering, control adapters can access the style object that is associated with the control. The control-adapter base class provides a Style property that can be used to access the control's style object. However, adapters must use a different accessor function to retrieve style properties, so that style inheritance behavior can be applied. To facilitate this, the Style base class provides an additional indexer property that takes two parameters: the property key and a Boolean argument to specify whether inheritance should be applied.
For instance, the following code example accesses the font name by using the FontNameKey field of a control, and sets inheritance to true.
String fontName = NewStyle[Style.FontNameKey, true];
See Also
Tasks
Walkthrough: Implementing a New Style
Reference
<Style> Element
Style
StyleSheet