WP7 entry-(2) themes, styles, and templates

Source: Internet
Author: User

Themes, styles, and templates
1. theme
Theme has two options: Background and Accent color.
(1) obtain the topic background
Theme Resources in C: \ Program Files \ Microsoft SDKs \ Windows Phone \ v7.0 \ Design. xaml, which is also an object of the Framework Element, which can be accessed by developers.
(2) obtain the subject color
Access the value of accent colors through the system's Resource attribute PhoneAccentBrush. You can directly access accent colors in the XAML Code. The Code is as follows: <TextBlock Foreground = "{Static Resource PhoneAccentBrush }"... />, you can also access it with managed code, such:
(Brush) Application. current. resources ["PhoneAccentBrush"]; // you can use the resource dictionary to obtain more resource elements in the system, including color values and fonts.
2. style-style
The style in wp7 can only be stored in the Resources of the application or in the Resources of the current XAML document. The elements used to change the page are properties, so that the primary colors have a more unified appearance, more unified setting of attribute values makes program maintenance easier.
(1) Application Scope of styles
It refers to the file code area that the style can work in. It defines the style in the <Phone: PhoneApplication. resources>, this style is only valid for the current file. All frameworkelements in the file can reference this style, however, when you need to change the file to be referenced by the XAML file elements in the project, you must define the style code in the application configuration file App. in xaml. The following uses Image as an example:
1> in the current file MainPage. xaml:
<Phone: PhoneApplicationPage. Resources>
<Style x: Key = "Image1" TargetType = "Image"> // x: Key = "" indicates the Style name; targetType = "" specifies the type of the style.
<Setter Property = "Width" Value = "180"/>/// <Setter...> to set a unified Attribute Value
......
<Setter Property = "Stretch" Value = "Fill"/>
</Style>
</Phone: PhoneApplicationPage. Resources>
Then write the following in the attributes of the Image control:
<Image Margin = "," Name = "p1" Style = "{StaticResource Image1}" Source = "/wp7 experiment 3; component/Images/12.png"/>
<Image Margin = ", 50," Name = "p2" Style = "{StaticResource Image1}" Source = "/wp7 experiment 3; component/Images/11.png"/>
....
Among them, p1 and p2 have the same attributes set in the style, and other attributes can be set by yourself.
2> in the App. in xaml, set <Style...>... </Style> write <Application. resource> </Application. resource>.
(2) You can also use Expression Blend 4 for Windows Phone to create a style. EBlend is similar to Adobe's PS, and it will be clearer. I won't write more here...
Extension ------ style inheritance
Styles can be enhanced or changed through the inheritance process. You only need to set the BasedOn attribute of the Style to the previously defined Style, for example:
<Style x: Key = "A1" TargetType = "Button">... </Style>
<Style x: Key = "B1" TargetType = "Button">
...
BasedOn = "{StaticeResource A1 }"
<Setter Property = "HorizontalAlignment" Value = "Left"/>...
</Style>
<Style x: Key = "B2" TargetType = "Button">
...
BasedOn = "{StaticeResource A1 }"
<Setter Property = "HorizontalAlignment" Value = "Right"/>...
</Style>

..........
Explanation: in the referenced code you write, you can reference the two different styles B1 and B2 mentioned above.
3. Template-Template
A template allows you to set and modify the attributes of an element to customize the widget's appearance. You can thoroughly change the widget's appearance, fill, and other attributes, and retain all its own attributes and events. Unlike styles, for example, it is difficult to make a Button into an image type control using styles, but templates are very convenient.
(1) Use templates
The application scope of Template and Style is the same, but there is a difference in definition. The Code of Template in MainPage. xaml is as follows:
<Phone: PhoneApplicationPage. Resources>
<ControlTemplate x: Key = "ImageControlTemplate1" TargetType = "Image"> // ControlTemplate indicates creating a template resource.
<Grid> // TargetType indicates the template type.
... // Defines template attributes and attribute values. For example, you can add an Image control ..
</Grid>
</ControlTemplate>
</Phone: PhoneApplicationPage. Resources>
The difference between a Template and a Style is that a Style uses a Setter set to customize control attributes, while a Template overwrites control attributes through node elements.
(2) You can also use Expression Blend 4 for Windows Phone to create a template...
4. Use templates in styles
You can use the <Setter Property = "Template"> method to specify a Template. In this way, you can use both the style and Template in a control, in some complex projects, maintenance of programs will be facilitated.
Take adding an Image to the Button as an example:
<Phone: PhoneApplicationPage. Resources>
<Style x: Key = "Button1" TargetType = "Button"> // x: Key = "" indicates the Style name; targetType = "" specifies the type of the style.
<Setter Property = "Width" Value = "180"/>/// <Setter...> to set a unified Attribute Value
......
<Setter Property = "Template"> // it is important to specify the set Property value as the custom Template Code so that it can be referenced by the style.
<Setter. Value> // The template is as follows:
<ControlTemplate TargetType = "Image">
<Grid>
<Image Source = "/Img; component/png/1.png" Stretch =" Fill "> .........
</Grid>
</ControlTemplate>
</Setter. Value>
</Setter>
</Style>
</Phone: PhoneApplicationPage. Resources>
You only need to specify the Style attribute value in the Button after definition. You do not need to set the Template attribute value, so you can apply the Template to the Button control ..
Extension ---
You can also <Setter Property = "? "> </Setter>, for example
<Setter Property = "Foreground">
<Setter. Value> // The following is a gradient paint brush.
<LinearGradientBrush>
<GradientStop Offset = "0" Color = "Pink">
....
</LinearGradientBrush>
</Setter. Value>
</Setter>

Note: I am a little sparrow that can't even be called by cainiao. I wrote something very basic and little code. I first understood the theory and then practiced it in depth, I have accumulated it for myself and shared it with friends...

 

 

Http://www.cnblogs.com/kefira/archive/2012/11/06/WP.html

Themes, styles, and templates
1. theme
Theme has two options: Background and Accent color.
(1) obtain the topic background
Theme Resources in C: \ Program Files \ Microsoft SDKs \ Windows Phone \ v7.0 \ Design. xaml, which is also an object of the Framework Element, which can be accessed by developers.
(2) obtain the subject color
Access the value of accent colors through the system's Resource attribute PhoneAccentBrush. You can directly access accent colors in the XAML Code. The Code is as follows: <TextBlock Foreground = "{Static Resource PhoneAccentBrush }"... />, you can also access it with managed code, such:
(Brush) Application. current. resources ["PhoneAccentBrush"]; // you can use the resource dictionary to obtain more resource elements in the system, including color values and fonts.
2. style-style
The style in wp7 can only be stored in the Resources of the application or in the Resources of the current XAML document. The elements used to change the page are properties, so that the primary colors have a more unified appearance, more unified setting of attribute values makes program maintenance easier.
(1) Application Scope of styles
It refers to the file code area that the style can work in. It defines the style in the <Phone: PhoneApplication. resources>, this style is only valid for the current file. All frameworkelements in the file can reference this style, however, when you need to change the file to be referenced by the XAML file elements in the project, you must define the style code in the application configuration file App. in xaml. The following uses Image as an example:
1> in the current file MainPage. xaml:
<Phone: PhoneApplicationPage. Resources>
<Style x: Key = "Image1" TargetType = "Image"> // x: Key = "" indicates the Style name; targetType = "" specifies the type of the style.
<Setter Property = "Width" Value = "180"/>/// <Setter...> to set a unified Attribute Value
......
<Setter Property = "Stretch" Value = "Fill"/>
</Style>
</Phone: PhoneApplicationPage. Resources>
Then write the following in the attributes of the Image control:
<Image Margin = "," Name = "p1" Style = "{StaticResource Image1}" Source = "/wp7 experiment 3; component/Images/12.png"/>
<Image Margin = ", 50," Name = "p2" Style = "{StaticResource Image1}" Source = "/wp7 experiment 3; component/Images/11.png"/>
....
Among them, p1 and p2 have the same attributes set in the style, and other attributes can be set by yourself.
2> in the App. in xaml, set <Style...>... </Style> write <Application. resource> </Application. resource>.
(2) You can also use Expression Blend 4 for Windows Phone to create a style. EBlend is similar to Adobe's PS, and it will be clearer. I won't write more here...
Extension ------ style inheritance
Styles can be enhanced or changed through the inheritance process. You only need to set the BasedOn attribute of the Style to the previously defined Style, for example:
<Style x: Key = "A1" TargetType = "Button">... </Style>
<Style x: Key = "B1" TargetType = "Button">
...
BasedOn = "{StaticeResource A1 }"
<Setter Property = "HorizontalAlignment" Value = "Left"/>...
</Style>
<Style x: Key = "B2" TargetType = "Button">
...
BasedOn = "{StaticeResource A1 }"
<Setter Property = "HorizontalAlignment" Value = "Right"/>...
</Style>

..........
Explanation: in the referenced code you write, you can reference the two different styles B1 and B2 mentioned above.
3. Template-Template
A template allows you to set and modify the attributes of an element to customize the widget's appearance. You can thoroughly change the widget's appearance, fill, and other attributes, and retain all its own attributes and events. Unlike styles, for example, it is difficult to make a Button into an image type control using styles, but templates are very convenient.
(1) Use templates
The application scope of Template and Style is the same, but there is a difference in definition. The Code of Template in MainPage. xaml is as follows:
<Phone: PhoneApplicationPage. Resources>
<ControlTemplate x: Key = "ImageControlTemplate1" TargetType = "Image"> // ControlTemplate indicates creating a template resource.
<Grid> // TargetType indicates the template type.
... // Defines template attributes and attribute values. For example, you can add an Image control ..
</Grid>
</ControlTemplate>
</Phone: PhoneApplicationPage. Resources>
The difference between a Template and a Style is that a Style uses a Setter set to customize control attributes, while a Template overwrites control attributes through node elements.
(2) You can also use Expression Blend 4 for Windows Phone to create a template...
4. Use templates in styles
You can use the <Setter Property = "Template"> method to specify a Template. In this way, you can use both the style and Template in a control, in some complex projects, maintenance of programs will be facilitated.
Take adding an Image to the Button as an example:
<Phone: PhoneApplicationPage. Resources>
<Style x: Key = "Button1" TargetType = "Button"> // x: Key = "" indicates the Style name; targetType = "" specifies the type of the style.
<Setter Property = "Width" Value = "180"/>/// <Setter...> to set a unified Attribute Value
......
<Setter Property = "Template"> // it is important to specify the set Property value as the custom Template Code so that it can be referenced by the style.
<Setter. Value> // The template is as follows:
<ControlTemplate TargetType = "Image">
<Grid>
<Image Source = "/Img; component/png/1.png" Stretch =" Fill "> .........
</Grid>
</ControlTemplate>
</Setter. Value>
</Setter>
</Style>
</Phone: PhoneApplicationPage. Resources>
You only need to specify the Style attribute value in the Button after definition. You do not need to set the Template attribute value, so you can apply the Template to the Button control ..
Extension ---
You can also <Setter Property = "? "> </Setter>, for example
<Setter Property = "Foreground">
<Setter. Value> // The following is a gradient paint brush.
<LinearGradientBrush>
<GradientStop Offset = "0" Color = "Pink">
....
</LinearGradientBrush>
</Setter. Value>
</Setter>

Note: I am a little sparrow that can't even be called by cainiao. I wrote something very basic and little code. I first understood the theory and then practiced it in depth, I have accumulated it for myself and shared it with friends...

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.