Save ComboBox choice for each item in a ListView

Topics: Getting Started, UI Architecture
Aug 4, 2013 at 2:47 PM

As a newcomer to Caliburn Micro, I'm trying to figure out how to reference (and save) each combobox choice made by the user in a WPF ListView (VS2012, targeting .NET 4.5). The ListView definition is as follows:

cal:Message.Attach="[Event Drop] = [Action FileArrived($eventArgs)]"
ItemContainerStyle="{StaticResource ItemContStyle}">
        <GridViewColumn Header="Path" DisplayMemberBinding="{Binding ScriptPath}" Width="640"/>
        <GridViewColumn Header="Server" Width="160">
                    <ComboBox ItemsSource="{Binding Source={StaticResource SQLScriptServers}}" DisplayMemberPath="ServerName" SelectedValuePath="ServerName" cal:Message.Attach="[Event SelectionChanged] = [Action ScriptServerChosen]"></ComboBox>

The user drags in some SQL scripts and I want them to be able to choose the relevant server from a combobox which holds a list of previously selected servers - I need to limit the selection choices to that list. There's one combobox for each ListView item. Not knowing any better, I've done this with:

<CollectionViewSource Source="{Binding ChosenServers}" x:Key="SQLScriptServers"/>

So far, the XAML and related ViewModel code work fine - up to the proverbial point. The problem is that when a server is chosen for one of the list items, all the other items in the ListView get their combobox selection changed to that same value. My aim instead is to have different servers selectable for each list item (if the user so desires).

Caliburn Micro seems to work to a large extent by use of consistent naming between the XAML and the code behind. But in this case, I don't know how many scripts might be dragged into the ListView.

I think that the problem lies in the use of a single CollectionViewSource for the comboboxes in the ListView. But how else to link the XAML to the code behind?

Most grateful for any suggestions.

With thanks and regards

Sebastian Crewe