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