Windows Phone development (15): Resources

Source: Internet
Author: User

Living print is one of China's "Four Great Inventions", Bi yi after the invention of the living print, he soon found a problem, with the printing materials continue to increase, the number of Chinese characters to be used more and more, therefore, he must find an effective way to manage those with Chinese charactersCubeBody (for the moment, it is called a cube, but it is indeed a cube), so he and the Helper work together to record these cubes and put them in a marked place, the words used in the printing process can be obtained directly. If you don't need them, they can be put back for environmental protection and convenience.
This is a resource. Water, Air, and sunlight are resources. coal and iron minerals are resources, but some are renewable and some cannot be recycled.
What is resource? Resources exist objectively. All disposable or reusable things that can be used when we need them, such as human resources and human resources.
If you have made web pages, you should understand what CSS is for. In fact, the resources we will discuss today are basically the same as those of CSS style sheets, that is, to save frequently used things, available for useProgramYou do not need to set a style for each control. You can save the style to the resource list.

Next, let's take a look at this section of XAML. There are four textblocks on it. I want the font size of each textblock TO BE 37.5. Of course, simple values can be easily set. If the values are complex, as shown in the previous articleArticleThe template mentioned above makes it very painful to create a template for each control.

<Stackpanel orientation = "vertical"> <br/> <textblock text = "first text"/> <br/> <textblock text = "second text"/> <br/> <textblock text = "third text"/> <br/> <textblock text = "fourth text"/> <br/> </stackpanel>

How can this problem be solved? Because the font size is double, the namespace must be introduced first. How can this problem be solved? Because the font size is double, the namespace must be introduced first.

Xmlns: SYS = "CLR-namespace: system; Assembly = mscorlib"

Next, define a font size resource in the page resource set. Pay attention to setting the key. Each resource has a unique key, which is used by the application to find the corresponding resource. Next, define a font size resource in the page resource set. Pay attention to setting the key. Each resource has a unique key, which is used by the application to find the corresponding resource.

<Stackpanel orientation = "vertical"> <br/> <textblock text = "first text" fontsize = "{staticresource fontsize}"/> <br/> <textblock text = "Second text" fontsize = "{staticresource fontsize}"/> <br/> <textblock text = "third text" fontsize = "{staticresource fontsize}"/> <br /> <textblock text = "fourth text" fontsize = "{staticresource fontsize}"/> <br/> </stackpanel>

 

The resource reference method is very simple. Put it in a pair of braces (extension tag). staticresource indicates a static resource. Note that only static resources can be used in Silverlight. If it is WPF, there are dynamic resources, the space is followed by the Resource Key. Do not ask me why.

In another example, there are three buttons. I want them to 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"> <br/> <button content = "button 1" Height = "72" margin = "10, 10, "Name =" button1 "/> <br/> <button content =" button 2 "Height =" 72 "margin =, 0, 0 "name =" button2 "/> <br/> <button content =" button 3 "Height =" 72 "margin =" 10,174, 0, 0 "name =" button3 "/> <br/> </GRID>

Now I only need to declare a style in the resource set and apply it to each button.

<Phone: phoneapplicationpage <br/> X: class = "ressampleapp. page2 "<br/> xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "<br/> xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "<br/> xmlns: Phone =" CLR-namespace: Microsoft. phone. controls; Assembly = Microsoft. phone "<br/> xmlns: shell =" CLR-namespace: Microsoft. phone. shell; Assembly = Microsoft. phone "<br/> xmlns: D =" http://schemas.microsoft.com/expression/blend/2008 "<br/> xmlns: MC = "http://schemas.openxmlformats.org/markup-compatibility/2006" <br/> fontfamily = "{staticresource phonefontfamilynormal}" <br/> fontsize = "{staticresource quota}" <br/> foreground = "{staticresource phoneforegroundbrush} "<br/> supportedorientations =" portrait "orientation =" portrait "<br/> MC: ignorable = "D" D: designheight = "768" D: designwidth = "480" <br/> shell: systemtray. isvisible = "true"> <br/> <Phone: phoneapplicationpage. resources> <br/> <style X: Key = "buttonstyle" targettype = "button"> <br/> <setter property = "background"> <br/> <setter. value> <br/> <lineargradientbrush startpoint = "0.5, 0" endpoint = "0.5, 1 "> <br/> <gradientstop color =" yellow "offset =" 0 "/> <br/> <gradientstop color =" red "offset =" 1 "/> <br/> </lineargradientbrush> <br/> </setter. value> <br/> </setter> <br/> <setter property = "horizontalalignment" value = "Left"/> <br/> <setter property = "verticalignment" Value = "TOP"/> <br/> <setter property = "width" value = "185"/> <br/> <setter property = "height" value = "50" /> <br/> <setter property = "borderthickness" value = "0"/> <br/> </style> <br/> </phone: phoneapplicationpage. resources> </P> <p> <grid> <br/> <button content = "button 1" Height = "72" margin = "10, 10, "Name =" button1 "style =" {staticresource buttonstyle} "/> <br/> <button content =" button 2 "Height =" 72 "margin =", 92, 0, 0 "name =" button2 "style =" {staticresource buttonstyle} "/> <br/> <button content =" button 3 "Height =" 72 "margin =" 10,174, 0, 0 "name =" button3 "style =" {staticresource buttonstyle} "/> <br/> </GRID> </P> <p> </Phone: phoneapplicationpage>

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.