Create a custom WP7 topic-simple theme implementation

Source: Internet
Author: User

Source: http://www.windowsphonegeek.com/articles/Creating-WP7-Custom-Theme-ndash-Basic-Theme-Implementation

I will start with a length of 3ArticleSeries-"create WP7 custom themes". In this series, I will explain everything you need to know about the silvelight for Windows Phone 7 theme. First, I will start with a simple color-based example, and then I will verify how to implement a complex topic that contains some custom control templates and other custom logic, finally, I will share with you what you need to consider when considering custom topics.

    • Create a custom WP7 topic-simple theme implementation
    • Creating WP7 custom theme-complex theme
    • Creating WP7 custom theme-Best Practices

This is the first article, so I will talk about how to implement simple customization in SL for WP7.ProgramTopic.

When you create a complex WP7 program with many controls, it is necessary to maintain the UI consistency across all themes. This is also an important part of WP7 program verification requirements.

You have the following options:

1. Create a custom program topic

When you want your program to look the same under different themes (that is, the topic is irrelevant), creating a custom program topic becomes a good solution. Another benefit is that in this case, regardless of the system theme, your controls will look consistent and remain unchanged.

Note: adding a custom theme to your program will overwrite the default theme.

2. Use the default theme resource: such a program will have different effects based on the current mobile phone theme.

In this case, if you use some default controls provided by the SDK, such as: button, ListBox, Panorama, Ghost, and so on, your program will be consistent without doing anything, in addition to the themes of the current mobile phone. By default, Windows Phone uses resource dictionary as the topic resource-a key-containing objects that can be used in XAML and code2.

You can see more here.

Http://www.windowsphonegeek.com/tips/-wp7-theme-resources-tips

Let's get started.

Now let's start creating a custom topic. The first thing to mention is that all WP7 theme resources are in the following folder (x64)

C: \ Program Files (x86) \ microsoft sdks \ Windows Phone \ v7.0 \ Design

The following is the composition of the design folder.

In general, the final file you need to modify is as follows:

1) themeresource. XAML

This file contains all the solidcolorbrushes, colors, and textblock resources.

Here you can find a list of available resources theme resources for Windows Phone

2) system. Windows. XAML

This is a more complex file that contains styles/controltemplates for all default SDK controls, such as Textbox, ListBox, And button.

Note: No matter how you modify the style of the control, make sure that the final result is suitable for the metro design style. For example, changing the appearance of togglebutton or scrollviewer may be a bad idea, because your users still expect these controls to be In the WP7 Metro style. However, you can change the color at will.

3) portableuserinterface. Metro. compositefont

This file contains important information such as fontfamily and fontsize designed to the Metro interface. I suggest you take this file seriously. Try not to modify it.

Create a simple custom program topic

Follow these steps to create a simple custom topic:

1) Create an example Windows Phone application and add a new custom topic to it.

2) Copy themeresource. XAML to your WP7 program and change the resource to what you like. Creating an independent topic folder is not that important, or you can copy the file to the root directory. However, we recommend that you put the topic file in a separate folder. In this example, we will create a customeme folder and copy the file here.

NOTE 1: The file name is not important. It is important not to forget to copy all the content of the file. If you like, you can change the file name at will.

NOTE 2: You can only modify some of them.

NOTE 3: do not modify the values of X: Key and X: Name.

3) change resources: change colors, paint brushes, and so on to form a custom appearance. In our example, we will change the following color:

Phonebackgroundcolor-Basic Color of phonebackgroundbrush

Phoneforegroundcolor-Basic Color of phoneforegroundbrush

Phoneaccenetcolor-Basic Color of phoneaccentbrush

 

Note: you can find the list of available resources here: Theme resources for Windows Phone

Use Visual Studio

You can also use vs to write the following example:

 
<! -- Pink -->
 
<Color x: Key = "phoneaccentcolor"> # fff50c98 </color>
 
<! -- Modified color -->
 
<Color x: Key = "phoneforegroundcolor"> # ff84f4f9 </color>
 
<! -- Modified color -->
 
<Color x: Key = "phonebackgroundcolor"> # ff39264e </color>

Use expression Blend

Another option is to use the visual designer of expression blend so that you can easily customize the appearance of each control, you can also modify the categories of all resources and edit the controltemplate in a simple way. Blend is better when creating a topic, because you can immediately see the effect in the designer.

3.1 right-click Visual Studio and select "open in expression blend"

3.2 you will see a Security Message prompt, press Yes.

3.3 open the resources label in expressionblend and select resources. Xmal (this is the name of your custom resource file)

3.4 use the appropriate color selector to modify the expected color.

The final generatedCodeIt should be as follows:

 
<Resourcedictionary xmlns = "The http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
 
Xmlns: system = "CLR-namespace: system; Assembly = mscorlib">
 
<! -- Another resourced here! -->
<! -- Pink -->
 
<Color x: Key = "phoneaccentcolor"> # fff50c98 </color>
 
<! -- Modified color -->
 
<Color x: Key = "phoneforegroundcolor"> # ff84f4f9 </color>
 
</Resourcedictionary>
 
<! -- Modified color -->
 
<Color x: Key = "phonebackgroundcolor"> # ff39264e </color>
 
</Resourcedictionary>

3.5 Save the changes and return them to Visual Studio. You will see another message box, asking if you want to save your changes in blend, and clicking yes to all.

4. Open app. XAML and add the following code

<Application. Resources> <resourcedictionary. mergeddictionaries> <resourcedictionary source = "mthmtheme/themeresources. XAML"/>
 
</Resourcedictionary. mergeddictionaries> </resourcedictionary> </application. Resources>

Note 1: This code will overwrite the default style!

NOTE 2: Make sure that the path of the resource file is correct and compiled. For more information about resourcedictionary, see:

All about resourcedictionary in WP7

5) Now you have successfully rewritten the style.

The following figure shows the default SDK control and the SL for WP7 toolkit control.

The above is all about creating a simple custom program topic.

You can find all the code here:

Wp7customcomplextheme.zip

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.