wp7 contentpresenter - setting content to the same page
I use a page (named containerpage) with a ContentPresenter
(named PageContent) and set its content to a PhoneApplicationPage
instance (contentpage) in the page's OnNavigatedTo()
eventhandler. I also have a mainpage with a button "Show Form". When I click on that button, the program navigates to the containerpage, that sets its contentpresenter's content to the contentpage. My problem is: if I click on "show form", then press the back button and click on "show form" again, I get ArgumentException with the text
"The parameter is incorrect"
on line
this.PageContent.Content = contentpage;
in the containerpage's OnNavigatedTo()
eventhandler. I guess this is because I already set another ContentPresenter's Content to this contentpage (because navigating cr开发者_Python百科eates a new page), but if this is the problem, how can I unassign my contentpage from the previous ContentPresenter's Content?
As decyclone mentioned, your question would be a lot clearer with detailed code. That said, you might implement OnNavigatedFrom()
on your conatinerpage and set the Content
to null
.
You might want to consider how this design holds up if the app gets tombstoned on containerpage.
To be honest, I'm amazed that setting the Content
property of one page to be an instance of another page even works! I really would advise against that as a long term solution. If the content of the first page is dynamic based on some condition, then use different UserControl
s instead.
If the data for the UserControl
is not persistent between calls to ShowForm
, then you can just create a new instance each time and then you won't have the re-parenting problem.
If you can elaborate on your application scenario and what you are trying to achieve, then we might be able to provide a better answer.
精彩评论