Windows phone, create an instance of the page and show it

Is it possible to create an instance of PhoneApplicationPage from another project (in the same solution, but this should not be important, right?) And show it?

Well, I know that you can create another page with:

 MyPageInProjectB bPage= new MyPageInProjectB (); 

but how to show it?

I want to do the following: I have two projects, and I want to show the page of one project as part of another project and transfer data between them. So I thought it would be perfect:

 public partial class MyPageInProjectA : PhoneApplicationPage { private MyPageInProjectB bPage; public MyPageInProjectA() { InitializeComponent(); MyComplexObject objectIWantToPassToOtherPage = new MyComplexObject (); bPage= new MyPageInProjectB (objectIWantToPassToOtherPage); } private void ShowBPageButton_Click(object sender, EventArgs e) { // this is now what I want to do, but what doesn't work bPage.Show(); } } 

Or is there another way to transfer complex data between these pages?

I do not want to use query strings because sometimes it happens that the (De-) Serializer has problems with MyComplexObject .

I read how to navigate between both pages in this thread: How to redirect to a page that exists in a particular project, to another page in another project in the same solution? but I want to transfer a complex object from one page to another. How can i do this?

+4
source share
1 answer

Edit: Okay, now, having carefully read your question, I can give you a better answer.

Firstly, you cannot pass data to the page constructor, since the runtime itself handles instantiation during navigation, and you can only navigate using the NavigationService . However, you have other options.

One of them uses a query string, but if you do not want to use this, you can use PhoneApplicationService to store a complex object and read another page.

 // In source page MyComplexObject objectIWantToPassToOtherPage = new MyComplexObject (); PhoneApplicationService.Current.State["MyComplexObject"] = objectIWantToPassToOtherPage; NavigationService.Navigate(new Uri("/ProjectB;component/MyPageInProjectB.xaml", UriKind.Relative)); // In destination page constructor public MyPageInProjectB() { var myComplexObject = (MyComplexObject) PhoneApplicationService.Current.State["MyComplexObject"]; // ... } 

In addition, global variables are used. These are the only options I can think of.


To go to a page in your ProjectB class library, you need to use a uri similar to the following:

/{assemblyName};component/{path}

In your case, you can do the following:

NavigationService.Navigate(new Uri("/ProjectB;component/MyPageInProjectB.xaml", UriKind.Relative));

Please note that I am specifying the relative path here, so MyPageInProjectB.xaml must be in the root folder inside ProjectB for the above example to work.

+3
source

Source: https://habr.com/ru/post/1489727/


All Articles