How to bind to a list inside an observableCollection of custom objects?

I have a class that has 2 public variables a string and a List of a Custom Class.

I have setup Binding and it works great for the string but I can't get it to bind to the List.

Code Behind

public class RegKey { public string Name { get; set; } public List<CEKeys> Key { get; set; } public RegKey() { Key = new List<CEKeys>(); } } public class CEKeys { public string Path { get; set; } public string KeyName { get; set; } public string Value { get; set; } public string Type { get; set; } } public partial class SetValues { private ObservableCollection<RegKey> obcRegKey; public SetValues(List<RegKey> keysToSet) { InitializeComponent(); obcRegKey = new ObservableCollection<RegKey>(keysToSet); dgRegKeys.ItemsSource = obcRegKey; } private void button_Click(object sender, RoutedEventArgs e) { Console.WriteLine("test"); } } 


<DataGrid x:Name="dgRegKeys" Margin="0,0,0,40" ItemsSource="{Binding}" AutoGenerateColumns="False"> <DataGrid.Columns> <DataGridTextColumn Foreground="Black" Width="60" Header="Name" Binding="{Binding Name, Mode=TwoWay}" IsReadOnly="True" /> <DataGridTextColumn Foreground="Black" Width="140" Header="Value" Binding="{Binding Path=Key.Value, Mode=TwoWay}" IsReadOnly="False"/> <DataGridTextColumn Foreground="Black" Width="140" Header="Type" Binding="{Binding Path=Key.Type, Mode=TwoWay}" IsReadOnly="True"/> </DataGrid.Columns> </DataGrid> 

How can I bind to the List of CEKeys while making the Value editable? Once the Value is confirmed I will be creating the keys that are listed.

While typing this I came upon a second issue. Each regkey has a List of Keys. This is because the RegKey may need to set multiple keys for it to work correctly. How can I also display all the keys in the List?

by Mac_Attack18 via /r/csharp

Leave a Reply