Thank you.... and one final question

Jan 9, 2014 at 11:50 AM
Firstly thanks to those who have helped me out over the last month or so transform my app from code behind to a well structure caliburn/mvvm pattern. Its now so easy to manage!

I have a final question regarding views. On my home page I have 5 list boxes which show the "Top 5" scores from 5 golf tours. Is it possible to use a list of(listboxes) or user controls with the caliburn conventions? then rather than declaring 5 individual properties for each list I can just use a list/array.
<ListBox x:Name="Scores" ...
<ListBox x:Name="ABCScores"
<ListBox x:Name="123Scores" ...

Ideally I'm looking for someway to implement
<ListBox x:Name="Scores[0]"...

if this is not possible its not a problem

again thanks d.
Jan 9, 2014 at 12:00 PM
Edited Jan 10, 2014 at 9:56 AM
You can create a list of scores groups, with specific view-models and views.

What I mean is, every set of scores has to be wrapped in a ScoresGroupViewModel, something like
public class ScoresGroupViewModel : PropertyChangedBase, IHaveDisplayName
         public string DisplayName { get { ... } set { ... } }  //Store here the 'name' of the group, just like "ABCScores"...
         public ObservableCollection<ScoreViewModel> Scores { get; private set; }

         //Code omitted...
Every group would use the same view
<UserControl ...>
     <ListBox x:Name="Scores" ... /> <!-- Other than the individual scores, a proper header should be provided, displaying the DisplayName for group of scores -->
The view-model exposing all grouped scores, will use a simple ItemsControl to display all listboxes
<UserControl ...>
    <ItemsControl x:Name="ScoreGroups"/> <!-- Use the appropriate Panel here... probably a vertical oriented StackPanel would suffice -->
With this approach, scores groups are defined through view-model, and the view is dinamically built. In case a specific group needs a different view, you can inherit from the base view-model class, put there some more logic and create a specific view (something like 'Other scores', where just brief informations are displayed).

I hope this makes sense to you. Feel free to ask. :)
Jan 9, 2014 at 12:14 PM
Edited Jan 9, 2014 at 12:18 PM
ah that's how its done! great thanks I was pretty close in my attempts I'll give it a whirl tonight and let you know how I get on.... I need to get out of thinking that a viewmodel is a page; when its just a collection of stuff (technical term)
Jan 10, 2014 at 9:45 AM
Edited Jan 10, 2014 at 9:46 AM
It works! :-) It makes things so much easier just to enumerate the list rather than hard coding each control

thanks very much and have a great weekend!