Styling Controls
Programmers like to tinker with the look of controls. There are two ways to do so in Silverlight: minor adjustments can be made with styles, and wholesale redesigns with templates.
To illustrate how to use styles, we'll start with the program you just wrote. You can just make a copy, but the safest way is to create a new project and copy the XAML and the classes into the new namespace. Here are the steps:
Create a new project (let's call it BookStyles).
In the original Page.xaml, collapse the
Grid
as shown in Figure 7-18 and copy it.Figure 7-18. Collapse and copy the Grid
In the new Page.xaml, collapse the
Grid
and paste the oldGrid
over it.Back in the original Page.xaml.cs, collapse and copy the
Page
class (as Figure 7-19 shows) and paste it into the new project. Then copy and paste theusing
statements.Figure 7-19. Collapse and copy the Page class
In the new project, create a Book.cs file and then collapse and copy the
Book
class from the old project to the new one. Then copy and paste theusing
statements.Run the new project to ensure that everything is working properly.
Applying Styles Inline
Let's start by adding some inline styling to the TextBlock
for the "Title" prompt:
<TextBlock x:Name="TitlePrompt" Text="Title: " VerticalAlignment="Bottom" HorizontalAlignment="Right" ...
Get Programming .NET 3.5 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.