I´m currently learning the DataBinding in C# WPF and I´m trying to set the ItemsSource property of a DataGridComboBoxColumn.
I have a Class Material:
public class Material {
public static List<Material> loadedMaterials;
static Material() {
loadedMaterials = new List<Material>();
loadedMaterials.Add(new Material("TEST1", "", ""));
loadedMaterials.Add(new Material("TEST2", "", ""));
loadedMaterials.Add(new Material("TEST3", "", ""));
}
public string name { get; set; }
public string name2 { get; set; }
public string name3 { get; set; }
public Material(string n, string n2, string n3) {
name = n;
name2 = n2;
name3 = n3;
}
}
And a Datagrid:
<DataGrid x:Name="dg" ItemsSource="{Binding}" AutoGenerateColumns="false">
<DataGrid.Columns>
<DataGridComboBoxColumn Header="Name" SelectedItemBinding="{Binding name}"/>
</DataGrid.Columns>
</DataGrid>
The SelectedItemBinding is already working, but now I´m trying to set the ItemsSource.
I want all names, of the Materials stored in loadedMaterials.
I tried the following:
//K Refers to The Namespace the Material-Class is in
ItemsSource="{Binding Source={x:Static K:Material.loadedMaterials}, Path=name}
But instead of getting the List of all the names, the List the dropdown is using, is every Character the first Materials name has. ("T", "E", "S", "T", "1")
Is there a way to do get all the names from all the Materialss or do I have to create an extra List to achive this?