UNDERSTANDING CONTROL STYLES

If you've done any considerable amount of web development, especially using HTML, you've probably figured out the tremendous advantages of using CSS to control the look of various HTML elements in your website. CSS allows you to easily configure the various styles of controls, and its powerful cascading rules allow you to apply styles to multiple controls with minimal amounts of code. An additional benefit of CSS is that it allows you to separate the styles of the HTML elements from the HTML elements themselves. Although you can declare CSS style information inline next to the element to be affected, more often you put all the necessary style information in a separate file and include it at the top of the web page.

So far in this book, you've seen how to manipulate various Silverlight control styles by setting values for properties such as Background, BorderBrush, Margin, and Padding. All the work you've been doing has been inline and right next to the control being affected. In the following code, you can see how this would be a time-consuming task, especially with a set of Button controls that have similar style information:

<Button Margin=“10,10,5,5” Padding=“5” Background=“Beige” Foreground=“Black” Content=“Click Me” /> <Button Margin=“10,10,5,5” Padding=“5” Background=“Beige” Foreground=“Black” Content=“Click Me” /> <Button Margin=“10,10,5,5” Padding=“5” Background=“Beige” Foreground=“Black” Content=“Click Me” /> <Button Margin=“10,10,5,5” Padding=“5” ...

Get Beginning Windows® Phone 7 Application Development: Building Windows® Phone Applications Using Silverlight® and XNA® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.