I have a WPF ListView which is bound to a data source. In the ListView are dynamically created ComboBoxes, which I would like to bind to another data source to provide the Item
Corresponding C# code ( you can use it as pseudo-code ) :
public class ViewModel
{
public List<MyComboBoxItems> items { get; set; }
public int outCustomValue2 { get; set; }
public bool outCustomValue1 { get; set; }
public ViewModel()
{
items = new List<MyComboBoxItems>();
items.Add(new MyComboBoxItems());
items.Add(new MyComboBoxItems());
items.Add(new MyComboBoxItems());
items.Add(new MyComboBoxItems());
}
}
public class MyComboBoxItems
{
public List<MyComboBoxStrings> TestStrings { get; set; }
public MyComboBoxItems()
{
TestStrings = new List<MyComboBoxStrings>();
TestStrings.Add(new MyComboBoxStrings("val1"));
TestStrings.Add(new MyComboBoxStrings("val1"));
TestStrings.Add(new MyComboBoxStrings("val1"));
TestStrings.Add(new MyComboBoxStrings("val1"));
}
}
public class MyComboBoxStrings
{
string _testString;
public string TestString { get { return _testString; } }
public MyComboBoxStrings(string value)
{
_testString = value;
}
}
apply DataContext :
ViewModel vm = new ViewModel();
myList.DataContext = vm;