保留 Silverlight 视图的状态
我开始在 Windows Phone 上使用 silverlight 进行开发。据我了解,silverlight 中的 xaml 视图是无状态的。
如何保留带有列表框的视图,以便在返回该视图后,我不必重新加载该视图中的数据?
这是一个例子:
假设我有一些列表项,其中包含来自互联网的一些照片、文本等。 单击列表框项目时,我会进入相应项目的详细视图。当我返回时,重新加载列表框效率不高(从时间、处理、带宽等角度来看)。我怎样才能保存该视图,这样我就不必重新加载它?能做到吗?
更新:我刚刚在一个视图中启动了一个计时器并导航到另一个视图,当我返回时,计时器仍在运行(它是一个 Threading.Timer),所以这是否意味着视图不无状态并且在导航到其他视图时它们不会被破坏?
I am starting developing in silverlight for windows phones. As i understood, the xaml views in silverlight are stateless.
How can i preserve a view with a listbox so that after returning to it, i don't have to reload the data in that view?
Here is an example:
let's say i have some list items that have some photos,text etc. from the internet.
When clicking on a listbox item i go into a detailed view for the respective item. When i go back,reloading the listbox isn't efficient (from the perspective of time, processing, bandwich etc.). How can i save that view so that i don't have to reload it? Can it be done?
UPDATE: i just started a timer in a view and navigated to another and when i went back, the timer was still running ( it was a Threading.Timer), so does this mean that the views are not stateless and they are not destroyed when navigating to other views?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
视图本身可能是无状态的,但没有什么可以阻止它们绑定到跨视图保留的状态/数据。 Silverlight 更像是一个桌面应用程序,而不是 ASP.Net 应用程序。 如果视图中的计时器仍在运行(它们将会运行),那是因为该视图仍然缓存在某处(或者计时器本身正在阻止视图被释放)。
状态问题(在 WP7 应用程序上)更多地与您拥有的有限内存量相关,因此您需要小心保留的内容。
如果您的应用程序退出并重新启动,您将需要将数据存档在独立存储中(如果您不想在每次启动时从网络重新流式传输数据),但对于应用程序内保留,则取决于您的情况想要坚持观点之间。
Views may be stateless by themselves, but nothing stopping them being bound to states/data that is retained across views. Silverlight is more like a desktop app than an ASP.Net app. If your timer in a view is still running (which they will), that is because the view is still cached somewhere (or the timer itself is stopping the view from being disposed).
The problems with state (on a WP7 app) relate more to the limited amount of memory you have, so you need to be careful about what you retain.
If your app is exited and restarted you will need to archive the data in isolated storage instead (if you don't want to re-stream it from the web each time it starts), but for in app retention that is down to what you want to hang on to between views.
尝试使用 Mat laceys Tombstone 助手,它使得保存所有 Silverlight 页面的状态变得非常容易,事实上在大多数情况下,每个页面只需两行代码即可完成。
WP7 墓碑助手
Try using Mat laceys Tombstone helper, it makes saving the state of all Silverlight pages very easy to do, in fact in most cases it is just two lines of code per page to do.
WP7 Tombstone helper