题
我建立使用页面和导航服务的一个WPF应用程序。点击 之一的网页的采取的对象作为构造
Sub New(ByVal o As Object)
' This call is required by the Windows Form Designer.
InitializeComponent()
....
所以,导航到它我
Dim MyPage As New Page1(MyObject)
MyBase.NavigationService.Navigate(MyPage)
当我编辑的东西在页面,并返回,和我的空间我得到以下错误的前进出现该问题:
Cannot create object of type 'Page1'. CreateInstance failed, which can be
caused by not having a public default constructor for 'Page1'.
我在做什么错了?
解决方案
您需要告诉页面应该在内存持续下去,而不是被“卸载”每次在您离开和“重载”当你回来给它时间主机应用程序。这原来是很简单:只需添加保持活动属性到你的页面声明:
<Page x:Class="..." KeepAlive="True">
有趣的是,MSDN文档这样说:
页面被实例化并 导航到仅使用代码( 例如,调用导航),是 自动保持活着。
我没有发现,这样的话,从你的问题看来你没有任何发现它的方式。
不隶属于 StackOverflow