Ok so, I have a listview with several rows which is defined by setting the itemsource in the code. Within each row that’s generated I have a combobox. In the code I have another array of objects which is the collection that this combobox should display.
I basically want it so that for each row you can select an option from the list. The list of possibilities will always be the same, hence the array.
A little bit of code to help. This is what I have for XAML:
<ListView Name="lvVanList">
<ListView.View>
<GridView>
<DisplayMemberBinding="{Binding Path=Number}">Van</GridViewColumn>
<GridViewColumn Header="Rooms">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<ComboBox Name="cbSchemeList" ItemsSource="{Binding Path=_RoomList}" SelectedValue="{Binding Path=Room}" DisplayMemberPath="Name" />
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
The code behind:
private RoomList _RoomList;
public populateList()
{
this.lvVanList.ItemsSource = this.getVans;
this._RoomList = this.getRooms;
}
private class Room
{
string Name { get; set; }
int Windows { get; set; }
}
Unfortunately this shows a blank list when the combobox is open.
I do have a way around this by storing the possibilities list in the object which is binded to each row but I’m sure I should be able to just use a single collection.
It’s tough to describe so if there’s any information I’ve missed or it’s not understandable please let me know.
Thanks in advance
The problem is that the binding path (
_RoomList) is relative to theDataContextof each entry of the ListView. And thatDataContextis the displayed item and not your view.You can solve this in multiple ways:
ElementName