使用 Caliburn.Micro 将属性和方法绑定到单个元素
所以,我对 Silverlight 开发相当陌生,我正在尝试找出并使用 Caliburn.Micro 框架。据我所知,CM 使用约定将视图模型中的属性与视图中的元素进行匹配,并且默认约定可以在 CM 的 ConventionManager 类中找到。
我的情况是这样的:我有一个名为“Libraries”的 TreeView(使用 Silverlight Toolkit),并且我已成功将视图模型中的 ObservableCollection 类型的属性绑定到 TreeView。该属性也被命名为“图书馆”,因此 CM 完成了其余的工作。
现在,我想在视图模型中创建一个属性,该属性将使用 TreeView 的 SelectedItem 设置。我应该如何使用 CM 的约定来做到这一点?我应该给该房产起什么名字?
最后,我希望在触发 TreeView 的 SelectedItemChanged 事件时调用视图模型中的一个方法。我应该为该方法命名什么,以便通过约定来完成?
谁能帮忙解决这个问题吗?
艾森伯格...艾森伯格...(以我最好的本·斯坦模仿)
谢谢, David
编辑:我还应该注意到,我已经修改了 CM 程序集,以将以下行添加到 ConventionsManager 的构造函数中,因为它之前已从 CM dll 的 Silverlight 版本中排除:
AddElementConvention(TreeView.ItemsSourceProperty, "SelectedItem", " SelectedItemChanged");
So, I am fairly new to Silverlight development and I am trying to figure out and use the Caliburn.Micro framework. I understand that CM is using convention to match properties in the view model with elements in the view and that the default conventions can be found in the ConventionManager Class of CM.
My situation is this: I have a TreeView (using the Silverlight Toolkit) named "Libraries" and I have successfully bound a property of type ObservableCollection in my view model to the TreeView. The property is also named "Libraries" so CM did the rest.
Now, I want to create a property in the view model that will be set with the TreeView's SelectedItem. How should I do this using CM's conventions? What should I name the property?
And finally, I want a method in the view model to be called when the TreeView's SelectedItemChanged event is fired. What should I name the method so that this is accomplished via convention?
Can anyone help with this?
Eisenberg...Eisenberg...(in my best Ben Stein impersonation)
Thanks,
David
EDIT: I should also note that I have modified the CM assembly to add the following line to the ConventionsManager's constructor as it was previously excluded from the Silverlight version of CM dll:
AddElementConvention(TreeView.ItemsSourceProperty, "SelectedItem", "SelectedItemChanged");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够创建一个名为 SelectedLibrary 或 ActiveLibrary 的公共属性,CM 将完成其余的工作。如果这不起作用,您可以随时依靠操作:
编辑:您需要属性设置器和触发方法吗?
You should be able to create a public property named SelectedLibrary or ActiveLibrary and CM will do the rest. If that doesn't work you can always fall back on an Action:
edit: do you need a property setter and a method to fire?