如何从视图模型导航到视图

发布于 2024-10-31 14:47:01 字数 442 浏览 1 评论 0原文

我想知道是否有人可以就我遇到的 Silverlight 问题提供一些指导?

我现在正在做的是使用 MVVM 模式在 Silverlight 中构建一个页面来检索和显示我的数据。我的页面将是一个标准的“列表”类型页面,它使用数据网格来显示和过滤数据。

我想做的是,如果用户单击此列表页面上的编辑按钮,我想导航到详细信息页面,其中将包含一个数据表单,我想将其绑定到绑定到的相同数据集合列表页面的数据网格。我认为必须发生的是列表视图模型必须创建详细信息页面并将详细信息页面数据上下文设置为其自身(作为列表视图模型的实例)。我不确定如何创建视图、导航到它并将引用传递给视图模型。

您可能想知道为什么我想要一个包含集合的详细信息页面。这样我就可以模拟用户在当前访问应用程序中熟悉的行为。大多数情况下,当用户过滤列表视图时,它会派上用场,他们可以进入一个页面,在其中可以导航和编辑过滤器中的任何结果,而无需重复打开和关闭详细信息页面。

I'm wondering if someone could give me some guidance on a Silverlight problem I'm having?

What I am doing now is building a page in Silverlight using the MVVM pattern to retrieve and display my data. My page will be a standard "List" type page that uses the datagrid to display and filter data.

What I would like to do is, If the user clicks an edit button on this list page, I would like to navigate to a details page which will contain a dataform that I want to bind to the same collection of data that is bound to the datagrid of the list page. What I'm thinking has to happen is the List ViewModel has to create the Details Page and set the Details Page datacontext to itself (being the instance of the List ViewModel). I'm not sure how I would create the view, navigate to it and pass the reference to the view model.

You may be wondering why i would want a details page that takes a collection. This is so I can simulate behaviour that my user is familiar with in their current access application. Mostly, it comes in handy when the user filters the list view they are able to enter a page where they could navigate and edit any of the results from their filter without having to open and close the details page repeatedly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相权↑美人 2024-11-07 14:47:01

MVVM 非常适合于此。您假设它们共享相同的视图模型是正确的,因为数据是相同的,并且您可以同时自动更新两个位置中的数据。

但是,我会避免使用视图模型来创建视图。这通常被视为实现 MVVM 的错误方法,因为它创建了从视图模型到视图的耦合,这可能会给您带来麻烦。

这篇博文。

MVVM is well suited to this. You are right in assuming they both share the same view model, as the data is the same and you can automatically update the data in both locations at once.

However, I would avoid getting the view model to create the views. This is often seen as the wrong way to implement MVVM as it creates a coupling from the view models to the views which may get you into trouble later.

A solution with sample code is described in this blog post.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文