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
Gridas shown in Figure 7-18 and copy it.
Figure 7-18. Collapse and copy the Grid
In the new Page.xaml, collapse the
Gridand paste the oldGridover it.Back in the original Page.xaml.cs, collapse and copy the
Pageclass (as Figure 7-19 shows) and paste it into the new project. Then copy and paste theusingstatements.
Figure 7-19. Collapse and copy the Page class
In the new project, create a Book.cs file and then collapse and copy the
Bookclass from the old project to the new one. Then copy and paste theusingstatements.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" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access