This is a migrated thread and some comments may be shown as answers.

Bindable property collection

2 Answers 87 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Petr
Top achievements
Rank 1
Petr asked on 21 Sep 2015, 03:53 PM

Is it possible to use a collection that can be bound to as a property? Property collection is always of type TrackedList and it does not support data binding.

 

Ima leave out implementation of INotifyPropertyChanged and some other stuff so the example is as short as possible.

Let's say we have 2 entities, Company and Employee. The only interesting property is that of Company, called Employees and being a collection. We fetch the list of companies and bind combobox to it. We wanna display a list of Employees for currenctly selected Company.

 

public ObservableCollection<Company> Companies = new ObservableCollection<Company>(Model.Companies);
public Company SelectedCompany {get;set;}

<Combobox ItemsSource="{Binding Companies}" SelectedItem="{Binding SelectedCompany}/>
<Listbox ItemsSource="{Binding SelectedCompany.Employees"/>

I haven't been able to implement the Employees property of Company object so it's a collection that can be bound to. So when I add/remove items the bound control is not informed.

 

Thanks in advance~

2 Answers, 1 is accepted

Sort by
0
Petr
Top achievements
Rank 1
answered on 21 Sep 2015, 04:25 PM
This is pretty much what I have problem with, sadly the resource linked on the page is not available anymore.
0
Petr
Top achievements
Rank 1
answered on 21 Sep 2015, 11:40 PM

Alright problem solved by defining the property as TrackedBindingList, however when you do that you have to provide data type for the collection.

 

companies.HasAssociation<Employee>(c => c.Employees)
    .WithOpposite(e => e.Company)
    .HasConstraint((c,​e) => c.ID == e.EmployeeID)
    .IsManaged();

Tags
Development (API, general questions)
Asked by
Petr
Top achievements
Rank 1
Answers by
Petr
Top achievements
Rank 1
Share this question
or