Implementing and extending styles and templates

If you plan to use the style in multiple pages of your app, you should create it in App.xaml or StandardStyles.xaml. If you plan to use the style within a single page, Visual Studio places the newly created Style resource within the Page.Resources section.

Styles can be defined without a Key, which causes the style to be applied for all controls of that TargetType. This is called an implicit style, in contrast with the styles that are explicit styles. For example, if you wanted all the TextBlock” controls in a page to have some properties set to the same value, you can apply the following style in XAML:

<Style TargetType=”TextBlock”>
<Setter Property=”FontSize” Value=”24″ />
<Setter Property=”Width “ Value=”200″ />

The implicit style will be applied to all TextBlocks in a page if the style is declared in the Page.Resources section or it will be applied to all TextBlocks in your app if it is added with the ResourceDictionary section in App.xaml.

You can also apply the default style to a TextBlock in the app by setting its Style to null. An important property of the Style class is BasedOn.

Gradients provide better performance than images.  However, carefully consider the use of gradients in app controls. Gradients can be distracting when used too often on a page. It’s better to use a gradient to highlight a particular control, which draws the attention of the user.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s