I am trying to implement simple master detail databinding C# WPF in Xaml. On the left side I have a listbox which is properly generated and on the right side I have a datagrid. When I click on left listbox I want my Datagrid to change accordingly. Currently I belive I have problem wtih SelectedItem path. Could someone give an advice?
public class Pipe
{
public string ID { get; set; }
public ObservableCollection<Node> nodes = new ObservableCollection<Node>();
}
public class Node
{
public int ID { get; set; }
public double Distance { get; set; }
}
ObservableCollection<Pipe> p = new ObservableCollection<Pipe>();
After populating my Pipe Class I bind it via
lstLines.DisplayMemberPath = "ID";
lstLines.ItemsSource = p;
Until now everything work correctly. Next in Xaml I bind my datagrid to the SelectedItem of Listbox via :
ItemsSource="{Binding Path=SelectedItem.nodes, ElementName=lstLines, Converter={StaticResource debugConverter}}
Here is the problem .... I cant find the correct path so my datagrid is populated base on selecteditem of list. I've tried several variations but without lack.
Your Path
is fine but you can bind only public
properties and your nodes
is a field:
public ObservableCollection<Node> nodes {get; set; }
you can initialize nodes
in the Pipe
constructor, but it must be a property