I have two xamDataGrids one with Persons and one with Jobs and I'm using DataContext to bind to ObservableCollections Persons and Jobs (every person has a list with jobs). Here are my bindings:
DataSource="{Binding Path=Persons}"
DataSource="{Binding Path=Persons/Jobs}"
The problem I have is if I select a person in first grid it doesn't show the related jobs in the second grid, not even when using :
IsSynchronizedWithCurrentItem="True" .
Any ideas ?
Not sure but I guess that's because in your former pattern you were creating a NEW CollectionView each time you called PersonsView.
Interesting enough if I expose this from Firm class:
public List<Person> People { get { return people;} set { people = value;}}
public CollectionView PersonsView { get; set ; }
and change the constructor to this :
public Window1()
{
InitializeComponent();
var firm = new Firm();
firm.PersonsView = new CollectionView(firm.People);
layout.DataContext = firm;
}
it actually works...go figure !
Thank you for your sample projects, seems to work fine. But getting closer to my model and using your Person & Jobs classes I've created a higher level class Firm:
public class Firm
private List<Person> people;
public Firm()
people = new List<Person>();
for (int i = 0; i < 5; i++)
Person p = new Person();
p.Name = "Name " + i;
List<Jobs> j = new List<Jobs>();
j.Add(new Jobs() { Title = p.Name + " Title" + i });
p.Jobs = j;
people.Add(p);
public CollectionView PersonsView { get { return new CollectionView(people); } set { } }
changed the Window constructor to :
layout.DataContext = new Firm();
and the bindings to:
DataSource="{Binding Path=PersonsView, Mode=TwoWay}"
DataSource="{Binding PersonsView/Jobs}"
...bang! no more syncronization...why ?
I am attaching a working sample project with this. Please point out where is the difference between the two scenarios.
It doesn't work.
This is the modelI'm working with:
Firm
-> CollectionView(ObservableCollection<Person>) -> ObservableCollection<Jobs>
-> FirmDetail
and I'm setting
layout.DataContext = Firm;