wp7 contentpresenter - 将内容设置到同一页面
我将页面(名为containerpage)与ContentPresenter
(名为PageContent)一起使用,并将其内容设置为页面的OnNavigateTo()<中的
PhoneApplicationPage
实例(contentpage) /code> 事件处理程序。我还有一个带有“显示表单”按钮的主页。当我单击该按钮时,程序将导航到容器页面,将其内容演示者的内容设置为内容页面。我的问题是:如果我单击“显示表单”,然后按后退按钮并再次单击“显示表单”,我会收到带有文本的 ArgumentException
“参数不正确”
在线显示
this.PageContent.Content = contentpage;
在容器页面的 OnNavigateTo()
事件处理程序中 。我想这是因为我已经将另一个 ContentPresenter 的内容设置到此内容页面(因为导航会创建一个新页面),但如果这是问题所在,我如何从以前的 ContentPresenter 的内容中取消分配我的内容页面?
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 creates a new page), but if this is the problem, how can I unassign my contentpage from the previous ContentPresenter's Content?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 decyclone 提到的,如果有详细的代码,你的问题会更清楚。也就是说,您可以在 conatinerpage 上实现
OnNavigateFrom()
并将Content
设置为null
。您可能需要考虑如果应用程序在容器页面上被逻辑删除,那么此设计如何维持。
As decyclone mentioned, your question would be a lot clearer with detailed code. That said, you might implement
OnNavigatedFrom()
on your conatinerpage and set theContent
tonull
.You might want to consider how this design holds up if the app gets tombstoned on containerpage.
老实说,我很惊讶将一个页面的
Content
属性设置为另一个页面的实例竟然如此有效!我真的不建议将其作为长期解决方案。如果第一页的内容根据某些条件是动态的,则使用不同的 UserControl 来代替。如果
UserControl
的数据在调用ShowForm
之间不是持久的,那么您每次都可以创建一个新实例,这样就不会出现重新设置父子关系的问题。如果您能详细说明您的应用场景以及您想要实现的目标,那么我们也许能够提供更好的答案。
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 differentUserControl
s instead.If the data for the
UserControl
is not persistent between calls toShowForm
, 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.