Windows Phone development (17): URI ing

Source: Internet
Author: User

I have discussed the knowledge of navigation, controls, resources, styles, templates, and I believe that you should have a very intuitive understanding of the content of the UI. So what do we talk about today? I wonder if you find a problem during exercise navigation?

When we pass a parameter to the page, it is okay. However, if we use such a URI in XAML, can you ensure that it still works properly?

/Pageatest. XAML? Name = Xiaoqiang & age = 100

You found out, hey, what's going on? Why did you report an error? I don't know if I want to think about it. Why?

Okay. First, have you learned web development? Or, do you know HTML? Well, you have found the answer.

Haha, by the way, it is the problem of encoding and escaping. The "&" symbol also needs to be escaped in XAML, but you must have discovered that if you replace it with an escape character, it seems ugly, secondly, it is not safe. As you know, What does MVC use to access pages? Yes, it can pass the behavior of the controller and the URI is mapped.

Similarly, what is also needed in Silverlight navigation is still applicable in WP.

First, let's talk about how to solve this problem without using URI ing.

Right, use the C # code to navigate, so that the XAML escape can be avoided.

Private void button#click (Object sender, routedeventargs e) <br/>{< br/> navigationservice. navigate (New uri ("/pagerec. XAML? A = Hello & B = ", urikind. Relative); <br/>}< br/>

Let's take a look at the results. How can this problem be solved?

Don't be happy. The main character is still playing. We are talking about URI ing today, so we will use URI ing to solve this problem perfectly.

Is URI ing hard? It's not hard, it's very simple. We use two classes:

1. urimapper, which is used to manage the ing set. It is from the leader. It is very important that there are thousands of shrimps and crabs under it.

2. urimapping, these guys are eating together with the urimapper boss.

That is to say, a urimapper can contain 1 to n urimapping, and a boss can lead several Mazi. This is the principle of "a brother is a group of Wolves.

For various reasons, your super application may have n multiple ing solutions, so you can allow n urimapping. You know that a band cannot all play the violin. Obviously, you need the cooperation of other instruments.

Okay. How is Uri mapped? I believe that those who have played C # will be familiar with such statements:

String Ss = string. Format ("your character value is: {0}",-100 );

The above {0} is a placeholder, and 01234 is pushed down in turn. I believe everyone understands the above principle. First, in "your character value is: {0} "in {0}", and then replace {0} with-100, so the above string becomes: Your character value is-100.

The principle of Uri ing is the same, for example:

/Student/{ID} ---->/studentdetail. XAML? SID = {ID}

Do you know how the URI above maps?

Look at the left. Others are redundant. They are "pseudo" Soldiers used to confuse the enemy. The real data is {ID}, and the right arrow is the real URI address, it also has a {ID} pair. It finds {ID} in the pseudo URI on the left and replaces the {ID} on the right with its value }.

Understand? For example, if I upload a URI,/student/201201030, and the final ing is actually/studentdetail. XAML? SID = 201201030, right?

Do not understand? Let me give you some more information. Do you want to find out the rule?

/CAT/{CID} --->/Categ. XAML? Id = {CID}

/CAT/5025 --->/Categ. XAML? Id = 5025

/{ID}/{name} ---->/goodslist. XAML? Gid = {ID} & gname = {name}

/302/World 7 ----->/goodslist. XAML? Gid = 302 & gname = World 7

/{Sex}/{order}/{type} ---->/listmat. XAML? Sex = {sex} & ACORD = {order} & swtype = {type}

/Female/3/7 ------>/listmat. XAML? Sex = female & ACORD = 3 & swtype = 7

 

As for why "/" is used, it is not necessary to escape it. Second, in order for the Runtime Library to recognize the placeholder location, it can also be used as a separator.

How do you feel? Not yet? It doesn't matter. You can feel it when you play it together.

Step 1: Open the app. XAML. CS file and add URI ing to the app constructor.

# Region URI ing <br/> urimapper MNG = new urimapper (); <br/> urimapping mymapping = new urimapping () <br/> {<br/> uri = new uri ("/page/{p1}/{P2}", urikind. relative), <br/> mappeduri = new uri ("/pagerec. XAML? A = {p1} & B = {P2} ", urikind. relative) <br/>}; <br/> MNG. urimappings. add (mymapping); <br/> This. rootframe. urimapper = MNG; <br/> # endregion <br/>

Then, return to the home page and add the code to the Code navigation page.

<Hyperlinkbutton content = "navigation mapped by Uri" Height = "73" horizontalalignment = "Left" margin = "12,286, 0, 0 "name =" hyperlinkbutton1 "verticalalignment =" TOP "width =" 327 "navigateuri ="/page/You can see/pass through "/>

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.