Use of the WP7 Page base class and encapsulation of input parameters of any type

Source: Internet
Author: User

 

Most of the time, we want to add unified code to all pages (such as using a switch to control all page Jump animations, such as setting the color of all pages through an entry ).

Therefore, it is a good way to let all pages inherit the same Page base class. We can reuse any code that can be reused.

Okay. Now we will implement this base class. Name it SuperPage,

namespace PageNavTest
public class SuperPage:PhoneApplicationPage
{
}
}

Here, I have to thank the author who has always supported me for writing such an article with interest. I would like to thank the author again for a very good wp7 Development Forum, I will also post several high-quality articles to you later. Please contact me on the noodles.

Enter the subject:

In mainpage. xaml, we have two changes

<local:SuperPage 
xmlns:local="clr-namespace:PageNavTest"
x:Class="PageNavTest.MainPage"
</local:SuperPage>

In mainpage. cs, we also need to change one

 public partial class MainPage : SuperPage

 

Now, this Mainpage inherits SuperPage. Similarly, you can modify page1.xaml, page2.xaml, and page3.xaml. When these pages have common logic, you only need to modify them in Basepage instead of modifying other classes.

 

Next I will introduce a method for passing arbitrary parameters through page navigation:

As you may know, one implementation method is to use a global variable to save the parameter to a global variable. This method is good, but I may use another method, it may be a bit difficult to write. Don't laugh. I will combine the Superpage below to encapsulate any page Jump for more convenient use.

In the end, you may pass in arbitrary parameters like this.

TestInfo newInfo = new TestInfo ();
NewInfo. name = "put an arguemnet of TestInfo: 123435 ";
Object [] args = new object [1];
Args [0] = newInfo;
OpenPage ("/Page1.xaml", args); // passing parameters, jump to the page

On the redirected page, the input parameters are also very simple.

   protected override void OnPageIn(object[] obj)
{
TestInfo info = obj[0] as TestInfo;
test.Text = info.name;
}

I hope you like my article! If you have more ideas, please contact me in the Q & a area of the wp7 Development Forum (codewp7.com). I will be glad to know what you are thinking. At the same time, I can also find my figure in wp7 chat QQ Group 172765887. Thank you!

Please slam the source code

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.