在 WP7 中使用 Caliburn.Micro 将视图模型共享到多个视图

发布于 2024-10-31 03:12:21 字数 440 浏览 5 评论 0 原文

我目前正在开发一个需要同一视图模型的多个视图的项目。让我这样描述:

  • ViewModel:CustomerDetailsViewModel.cs(继承自 Screen 类)
  • View:CustomerDetails.cs(此视图将 CustomerDetailsViewModel 作为数据上下文,由 Caliburn.Micro 自动设置)
  • View:CustomerInfo.cs(现在这是视图,其中我想分享 CustomerDetailsViewModel,它可能已经通过 CustomerDetails 视图修改了一些数据)

我目前正在使用 NavigationService 导航到 CustomerInfo 视图。有没有办法将当前视图模型的引用传递给用户在 caliburn.micro 中导航到的视图?

预先感谢

idev

I am currently working on a project which requires multiple views of the same viewmodel. Let me describe this way:

  • ViewModel: CustomerDetailsViewModel.cs (inherited from Screen class)
  • View: CustomerDetails.cs (this view has CustomerDetailsViewModel as datacontext and this set automatically by Caliburn.Micro)
  • View: CustomerInfo.cs (now this is the view where I want to share CustomerDetailsViewModel, which could have some data already modifed via CustomerDetails view)

I am currently using NavigationService to navigate to CustomerInfo view. Is there any way to pass the reference of current viewmodel to the view which user is navigating to in caliburn.micro?

Thanks in advance

idev

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

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

发布评论

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

评论(2

贱人配狗天长地久 2024-11-07 03:12:21

使用附加属性 cal:Bind.Model="{Binding}" 将视图绑定到视图模型。
请参阅 http://caliburnmicro.codeplex.com/wikipage?title=All%20About% 20Actions“首先查看”部分。

或者,您也可以查看 cal:View.Context="MyContext" 附加属性,如下所述: http://caliburnmicro.codeplex.com/wikipage?title=Screens%2c%20Conductors%20and%20Composition同一 ViewModel 上的多个视图”部分。

Use the attached property cal:Bind.Model="{Binding}" to bind the view to the view model.
See http://caliburnmicro.codeplex.com/wikipage?title=All%20About%20Actions "View First" section.

Alternatively you can also look into the cal:View.Context="MyContext" attached property as described here: http://caliburnmicro.codeplex.com/wikipage?title=Screens%2c%20Conductors%20and%20Composition "Multiple Views over the Same ViewModel" section.

任谁 2024-11-07 03:12:21

将一两个属性添加到您的 App.xaml.cs 中。您在此处放入的任何内容都将在应用程序的整个生命周期中持续存在(但请记住,逻辑删除将导致该属性的值丢失)。如果要传递 ViewModel,则将 App.xaml.cs 中的关联属性设置为视图模型,然后在新页面加载时从同一属性读取。

Add a property or two to your App.xaml.cs. What ever you put in here will persist throughout the lifetime of the application (keep in mind that tombstoning will cause this property's value to be lost though). If you want to pass a ViewModel then setyour associated property in App.xaml.cs to the view model and then when the new page loads have it read from that same property.

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