Movable type printing is one of China's "four big Inventions", after the invention of movable type, he quickly found a problem, with the increasing number of printed materials, to use more and more Chinese characters, so he must find an effective way to manage those carved with Chinese characters of the cube (called the cube, Actually is a cube), so, he and the assistants work together, for these cubes to record, marked to put, in the printing process to use what words, directly take out, no need to put back, both environmentally friendly and convenient.
This is the resources, water, air, sunlight is also a resource, coal, iron mineral is also a resource, but some renewable, some non-renewable.
What is a resource? Resources are objective, when we need to take advantage of all the things that can be controlled or re-assembled, such as human resources, network resources and so on.
If you have done a Web page, you should understand what CSS is used to do, in fact, the resources we are discussing today, and the concept of CSS style sheet basically the same, is to save some of the frequently used things, can be repeated in the application of the call, so that we do not have to set the style for each control, We can save the style to a list of resources and use it to remove it without repeating the definition.
Here's a look at this XAML, there are 4 TextBlock, I now want each TextBlock font size is 37.5, of course, simple values can be easily set, if the value is very complex, such as the previous article said the template, then you are very painful, to make a template for each control.
- <stackpanel orientation= "Vertical" >
- <textblock text= "First piece of text"/>
- <textblock text= "Second block of text"/>
- <textblock text= "Third piece of text"/>
- <textblock text= "Fourth block of text"/>
- </StackPanel>
How do you do it? Because the font size is a double type, you first introduce namespaces. How do you do it? Because the font size is a double type, you first introduce namespaces.
- xmlns:sys= "Clr-namespace:system;assembly=mscorlib"
Next, define a font size resource in the page resource collection, note that to set the key, each resource has a unique key, and the application uses this key to find the corresponding resource. Next, define a font size resource in the page resource collection, note that to set the key, each resource has a unique key, and the application uses this key to find the corresponding resource.
- <stackpanel orientation= "Vertical" >
- <textblock text= "First block of text" fontsize= "{StaticResource FontSize}"/>
- <textblock text= "Second block of text" fontsize= "{StaticResource FontSize}"/>
- <textblock text= "Third block of text" fontsize= "{StaticResource FontSize}"/>
- <textblock text= "Fourth block of text" fontsize= "{StaticResource FontSize}"/>
- </StackPanel>
The reference to the resource is simple, put in a pair of curly braces (extended markup), StaticResource is a static resource, note that only static resources in Silverlight, if WPF, and dynamic resources, the space is behind the resource key, do not ask me why.
Another example, there are three buttons, I hope they all have a gradient background color, horizontal left alignment, vertical top alignment, Width 185, height 50.
- <grid x:name= "Contentpanel" grid.row= "1" margin= "12,0,12,0" >
- <button content= "button One" height= "margin=" 10,10,0,0 "name=" Button1 "/>
- <button content= "button two" height= "margin=" 10,92,0,0 "name=" Button2 "/>
- <button content= "button three" height= "margin=" 10,174,0,0 "name=" Button3 "/>
- </Grid>
Now I just declare a style in the resource collection and apply it to each button.
- <phone:phoneapplicationpage
- X:class= "Ressampleapp.page2"
- Xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"
- Xmlns:phone= "Clr-namespace:microsoft.phone.controls;assembly=microsoft.phone"
- Xmlns:shell= "Clr-namespace:microsoft.phone.shell;assembly=microsoft.phone"
- Xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"
- Xmlns:mc= "http://schemas.openxmlformats.org/markup-compatibility/2006"
- Fontfamily= "{StaticResource phonefontfamilynormal}"
- Fontsize= "{StaticResource phonefontsizenormal}"
- Foreground= "{StaticResource Phoneforegroundbrush}"
- supportedorientations= "Portrait" orientation= "Portrait"
- mc:ignorable= "D" d:designheight= "768" d:designwidth= "480"
- shell:systemtray.isvisible= "True" >
- <phone:PhoneApplicationPage.Resources>
- <style x:key= "ButtonStyle" targettype= "button" >
- <setter property= "Background" >
- <Setter.Value>
- <lineargradientbrush startpoint= "0.5,0" endpoint= "0.5,1" >
- <gradientstop color= "Yellow" offset= "0"/>
- <gradientstop color= "Red" offset= "1"/>
- </LinearGradientBrush>
- </Setter.Value>
- </Setter>
- <setter property= "HorizontalAlignment" value= "left"/>
- <setter property= "VerticalAlignment" value= "Top"/>
- <setter property= "Width" value= "185"/>
- <setter property= "Height" value= "/>"
- <setter property= "borderthickness" value= "0"/>
- </Style>
- </phone:PhoneApplicationPage.Resources>
- <Grid>
- <button content= "button One" height= "margin=" 10,10,0,0 "Name=" Button1 "style=" {StaticResource buttonstyle} "/>
- <button content= "button two" height= "margin=" 10,92,0,0 "name=" Button2 "style=" {StaticResource buttonstyle} "/>
- <button content= "button three" height= "margin=" 10,174,0,0 "name=" Button3 "style=" {StaticResource buttonstyle} "/>
- </Grid>
- </phone:PhoneApplicationPage>
Windows Phone Development (15): Resources