Windows Phone Development (15): Resources

Source: Internet
Author: User
Tags movable type

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.

    1. <stackpanel orientation= "Vertical" >
    2. <textblock text= "First piece of text"/>
    3. <textblock text= "Second block of text"/>
    4. <textblock text= "Third piece of text"/>
    5. <textblock text= "Fourth block of text"/>
    6. </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.

    1. 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.

    1. <stackpanel orientation= "Vertical" >
    2. <textblock text= "First block of text" fontsize= "{StaticResource FontSize}"/>
    3. <textblock text= "Second block of text" fontsize= "{StaticResource FontSize}"/>
    4. <textblock text= "Third block of text" fontsize= "{StaticResource FontSize}"/>
    5. <textblock text= "Fourth block of text" fontsize= "{StaticResource FontSize}"/>
    6. </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.

    1. <grid x:name= "Contentpanel" grid.row= "1" margin= "12,0,12,0" >
    2. <button content= "button One" height= "margin=" 10,10,0,0 "name=" Button1 "/>
    3. <button content= "button two" height= "margin=" 10,92,0,0 "name=" Button2 "/>
    4. <button content= "button three" height= "margin=" 10,174,0,0 "name=" Button3 "/>
    5. </Grid>


Now I just declare a style in the resource collection and apply it to each button.

  1. <phone:phoneapplicationpage
  2. X:class= "Ressampleapp.page2"
  3. Xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"
  5. Xmlns:phone= "Clr-namespace:microsoft.phone.controls;assembly=microsoft.phone"
  6. Xmlns:shell= "Clr-namespace:microsoft.phone.shell;assembly=microsoft.phone"
  7. Xmlns:d= "http://schemas.microsoft.com/expression/blend/2008"
  8. Xmlns:mc= "http://schemas.openxmlformats.org/markup-compatibility/2006"
  9. Fontfamily= "{StaticResource phonefontfamilynormal}"
  10. Fontsize= "{StaticResource phonefontsizenormal}"
  11. Foreground= "{StaticResource Phoneforegroundbrush}"
  12. supportedorientations= "Portrait" orientation= "Portrait"
  13. mc:ignorable= "D" d:designheight= "768" d:designwidth= "480"
  14. shell:systemtray.isvisible= "True" >
  15. <phone:PhoneApplicationPage.Resources>
  16. <style x:key= "ButtonStyle" targettype= "button" >
  17. <setter property= "Background" >
  18. <Setter.Value>
  19. <lineargradientbrush startpoint= "0.5,0" endpoint= "0.5,1" >
  20. <gradientstop color= "Yellow" offset= "0"/>
  21. <gradientstop color= "Red" offset= "1"/>
  22. </LinearGradientBrush>
  23. </Setter.Value>
  24. </Setter>
  25. <setter property= "HorizontalAlignment" value= "left"/>
  26. <setter property= "VerticalAlignment" value= "Top"/>
  27. <setter property= "Width" value= "185"/>
  28. <setter property= "Height" value= "/>"
  29. <setter property= "borderthickness" value= "0"/>
  30. </Style>
  31. </phone:PhoneApplicationPage.Resources>
  32. <Grid>
  33. <button content= "button One" height= "margin=" 10,10,0,0 "Name=" Button1 "style=" {StaticResource buttonstyle} "/>
  34. <button content= "button two" height= "margin=" 10,92,0,0 "name=" Button2 "style=" {StaticResource buttonstyle} "/>
  35. <button content= "button three" height= "margin=" 10,174,0,0 "name=" Button3 "style=" {StaticResource buttonstyle} "/>
  36. </Grid>
  37. </phone:PhoneApplicationPage>


Windows Phone Development (15): Resources

Related Article

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.