Have got myself very confused on this one – apologies if the answer is really obvious but I am quite new to programming.
I have a user control set up as a view which is loaded into a content control within my main view. The datacontext for the usercontrol (Called SetView) is set in the MainView. I can happily bind to the SetView to UserControlVM (called SetVM).
In the SetVM I load in an ObservableCollection of a class I have created:
public class WeightSet : Weights
{
public string BodyArea { get; set; }
public string ExerciseType { get; set; }
public int SetNumber { get; set; }
public static ObservableCollection<int> Reps { get; set; }
#region Constructor
//This is the main constructor
public WeightSet(string bodyarea, string exerciseType, int setNumber)
{
BodyArea = bodyarea;
ExerciseType = exerciseType;
SetNumber = setNumber;
Reps = new ObservableCollection<int>();
AddReps();
}
#endregion Constructor
#region Methods
public void AddReps()
{
for (int i = 1; i < 100; i++)
{
Reps.Add(i);
}
}
#endregion Methods
My SetView then has a ListView whose ItemsSource is
public ObservableCollection<WeightSet> Sets
Here is the xaml for the ListView:
<UserControl x:Class="CalendarTest.SetView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:forcombo="clr-namespace:CalendarTest.Model.Repository.Local_Data"
xmlns:VM="clr-namespace:CalendarTest.ViewModel"
mc:Ignorable="d"
d:DesignHeight="165" d:DesignWidth="300">
<Grid >
<StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding CurrentExercise}" Width="100" Height="40"></Label>
<Label Content="{Binding BodyArea}" Width="100" Height="40"></Label>
</StackPanel>
<ListView ItemsSource="{Binding Sets}">
<ListView.View>
<GridView>
<GridViewColumn Header="Set Number" DisplayMemberBinding="{Binding Path=SetNumber}" Width="100"></GridViewColumn>
<GridViewColumn Header="Select Reps" Width="120">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox Width="100" ItemsSource="{Binding Source={x:Static forcombo:WeightSet.Reps }}" ></ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Path=Reps}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</StackPanel>
</Grid>
When I load SetView I have my list of set numbers and a combobox with the staticlist. Here is a shot:

I cant seem to bind the selecteditem for the comboBox back to my ViewModel. Is there a way to set the selected item in the WeightSet Class? I need to be able to save the selected number?
I understand that I cant just bind to a property as the number of ComboBoxs will be decided by user? Any tips or corrections to my current design would be much appreciated
You can bind the
SelectedItemproperty on your combobox, and add a dependencyproperty in your WeightSet classxaml:
and the property
Then
SelectedItemin your Sets instances will be updated when a value is selected in the combobox.