ListBox & Cal:View.Context.

Topics: Conventions, UI Architecture
Feb 28, 2013 at 3:35 PM

This is probably just a misunderstanding on my part. I have a model e.g. Foo, which I'm using different views for, depending on where the Foo is displayed. I'm currently have two views for a Foo, ReadOnly and Editable.

So I have:
And I'm using a ContentControl when a Foo is selected, to view the current active Foo:
<ContentControl cal:View.Model="{Binding Path=ActiveFoo}" 
                            cal:View.Context="{Binding Path=ActiveFoo.State}" />
Which is all working fine.

I'm now adding a listbox to another area of MyApp, which I want to bind to a collection of FooViewModels, and have an additional view which defines how they appear within the listbox, so MyApp.Views.Foo.ListView

This is where I'm running into some trouble - I can set my listbox to have the property X:Name="Foos" - binding to "IList<FooViewModel>" and this will happily find and bind to MyApp.Views.FooView if present.

When I try to bind using a context:
<ListBox cal:View.Model="{Binding Path=Foos}" cal:View.Context="{Binding Path=ListView}"/>
I can't find the correct view to bind to.

I've had a crack at debugging and, rightly so, the problem seems to be that the type being passed through to the Caliburn "Transform" function is an ObservableCollection, for which I'm having difficulty locating the correct View (and also identifying the ViewModel I'm after).

Is this just a stupid approach I'm taking towards styling Listbox items? I could probably achieve the same effect with. I'm sort of the opinion I'm just doing something quite daft, and have missed a subtle piece of syntax.

Any comments either way appreciated, Ta.