Bindable property collection

3 posts, 0 answers
  1. Petr
    Petr avatar
    9 posts
    Member since:
    Apr 2014

    Posted 21 Sep 2015 Link to this post

    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. Petr
    Petr avatar
    9 posts
    Member since:
    Apr 2014

    Posted 21 Sep 2015 in reply to Petr Link to this post

    This is pretty much what I have problem with, sadly the resource linked on the page is not available anymore.
  3. DevCraft banner
  4. Petr
    Petr avatar
    9 posts
    Member since:
    Apr 2014

    Posted 21 Sep 2015 Link to this post

    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();

Back to Top