MVVMLight——将参数传递给 ViewModel 构造函数?
假设我有一个绑定到 Foo
对象集合的 ListBox,并且选定的 Foo
显示在内容控件中,内容模板是 FooView.
有没有办法让 FooView
将选定的 Foo
传递给 FooViewModel
的构造函数,这是它的数据上下文ViewModelLocator
?
Suppose I have a ListBox which is bound to a collection of Foo
objects, and the selected Foo
is displayed in a contentcontrol with the content template being a FooView
.
Is there a way that I can make it so that the FooView
passes the selected Foo
to the constructor of the FooViewModel
which is it's datacontext via the ViewModelLocator
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MainView模型
MainView
MainViewModel
MainView
我听说虽然 Visual Studio 中的工具不支持它,但 XML 规范确实允许您在构造函数中使用参数实例化一个类。我从未这样做过,但听说 .Net Rocks 播客上可以做到这一点。也可能仅与 WPF 相关,而不与 Silverlight 相关,因为 WPF 比 Silverlight 具有更多功能。没有多大帮助,但可能会让你走上正轨。
I heard that although the tooling in Visual Studio does not support it, the XML spec does allow you to instanciate a class with a parameter in the constructor. I've never done it, but heard that this was possible on the .Net Rocks podcast. May also be only relevant to WPF as opposed to Silverlight, as WPF has more features than Silverlight. Not much help, but may put you on the right track.