Before opening an example, I want to solve a small problem. Previously, I said in my first article that the Chinese version of Visual Studio express for Windows Phone does not have simplified Chinese, that's because I downloaded it on the English homepage. The language selection list contains only one Chinese character, but it is traditional. Later, I found that the windwos phone SDK has a Simplified Chinese version, by the way, I will also give it.
Http://www.microsoft.com/downloads/zh-cn/details.aspx? Familyid = 0a373422-6680-46a7-89e1-e9a468a14259 can be installed online. If your network speed is low, you can download the ISO image for local installation. -------------------------------- In the previous article, we learned about the lifecycle of the WP application and the trigger of each event. Today, let's discuss the framework and page together. I will not talk about things that are so boring about the theory. On msdn, let's create a WP application project and open the app. XAML. check the CS file to see if there is a "New World" in it "? 1. An app class, from
Application derivation, which is the same as in Silverlight. Of course, it doesn't matter if you are not familiar with silerlight. Let's just blow it down.
I think you have played C #, and you should have used Windows Forms applications in any case. Right, we often say that the winform project has a program in the windowsform project. for files such as CS, the entry point of the program is defined in it. At the end of main, there is such a line in the default Generation Code of vs: application. run (...);
Therefore, this application and that application have the same meaning and are responsible for coordinating various transactions throughout the application. 2. We will notice that the app has a public attribute rootframe, which is the main framework. a wp application has only one main framework. 3. There are pages under the main framework. The main framework can contain one or more pages. 4. The page concept is very understandable, just like a form we usually see, but it is called a page in Silverlight. Therefore, we can also think of a Web page. In Android, it is called an activity. In fact, it refers to the same thing, but it is called differently. As shown in. Okay. Let's see how the next page is made up.
Let's take a look at the XAML declaration section of the page.
[HTML]View plaincopyprint?
- <Phone: phoneapplicationpage
- X: class = "phoneapp. mainpage"
- 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"
- MC: ignorable = "D" D: designwidth = "480" D: designheight = "768"
- Fontfamily = "{staticresource phonefontfamilynormal }"
- Fontsize = "{staticresource phonefontsizenormal }"
- Foreground = "{staticresource phoneforegroundbrush }"
- Supportedorientations = "portrait" orientation = "portrait"
- Shell: systemtray. isvisible = "true">
- ........................
We can see that each page is a subclass of phoneapplicationpage, which inherits from the page class in Silverlight.
Because the program is intended for WP mobile phones, you must use phoneapplicationpage instead of the page class to avoid problems. The class attribute is the class name of the webpage class. There are two namespaces to note:
Xmlns: D = "http://schemas.microsoft.com/expression/blend/2008"
Xmlns: MC = "http://schemas.openxmlformats.org/markup-compatibility/2006" D can be understood as the state at design, D: designwidth = "480" means that this width and height are only valid at design, that is, the size we see in the designer does not mean that it is actually running. It may be automatically adjusted according to the screen of the mobile phone, therefore, we should not deliberately set the width and height of the page to avoid being fixed and cannot be adjusted automatically. What is MC? In terms of semantics, translation is about the content related to tag compatibility. here we can see MC: ignorable = "D", as mentioned above, D: designwidth is designed at the time of design, therefore, ignorable = "D" tells the compiler to ignore the value set during design during actual operation. Supportedorientations is used to set the page support direction. If we want the program to automatically adjust after the mobile phone screen is rotated by the user, the property will be modified accordingly.
The orientation attribute is used to set the default direction of the current page, vertical or horizontal. Next, let's do an exercise. Change supportedorientations to portraitorlandscape, CHANGE orientation to a value other than none, and then run and rotate the phone in different directions. How can this problem be solved? It's interesting that you have made many changes and tried it several times. Another one is shell: systemtray. isvisible = "true" is used to set whether to hide the system tray. When we set it to true, run the program and move the mouse to the top of the page and click it. Then we will see the system tray, such as the signal strength and remaining battery margin of the current mobile phone.