开发者

Caliburn Micro - automatic creation of ViewModel objects from a ItemSource binding of Model classes?

Is it possible in Caliburn Micro to inject a ViewModel object between the view and the model when binding to a collection of model objects?

For example, if I had a IShellViewModel with the following property:

IEnumerable<Foo> Foos { get; set; }

and a ListBox in the ShellView.xaml

<ListBox x:Name="Foos"/>

Which would use FooView to render the listbox items. Can Caliburn inject a collection of IEnumerable for the V开发者_Python百科iew to bind to? Or do I have to create a parallel collection of IEnumerable next to the original model's IEnumerable.


I'm not quite sure what you're asking, when you say 'which would use FooView to render the listbox items', do you mean you have 1 view which renders ALL of the items, or a view per item?

If it's the latter, then Caliburn.Micro has a convention where if you have a collection of view models (e.g IEnumerable<FooViewModel>) bound to an ItemsControl, then it will search for a FooView for each of the items and automatically bind the located view to that item's view model.

If you're asking if Caliburn.Micro can autogenerate ViewModel types from your model types, then no. How would it know what properties to expose? Normally a view model reshapes and enhances the functionality of a model, including presentation logic which would be specific to a particular UI technology.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜