Dick
Dick

Reputation: 443

Combobox is not populated with delayed (async) data despite databinding

This got me puzzled today and I stil l don't see what I miss. I've got a Windows 8 Store form with multiple comboboxes, 2 I show below. I can populate them using databinding to a number of Lists. This works. Now these lists are stored in the W8 local folder Storage and the program loads them back async but then it only populates the first 2 comboboxes. It does only update all comboboxes when I would delay "DataContext=this" with a few seconds or so. I would expect that when the List's are coming in async, the RaisePropertyChanged("SelectedClass") is called and populates the comboboxes but this is never fired it seems. I can leave away SelectedItem="{Binding SelectedClass}" in the XAML or the SelectedClass code without any change in behaviour.

This a part of the XAML:

<ComboBox x:Name="machinetype" HorizontalAlignment="Right" Margin="0,120,14,0" VerticalAlignment="Top" Width="250" Height="30" ItemsSource="{Binding prMachtype}" SelectedItem="{Binding SelectedClass}" DisplayMemberPath="Descript" Grid.Column="2"/>
<ComboBox x:Name="position" Margin="0,2328,510,0" HorizontalAlignment="Right" Width="74" VerticalAlignment="Top" Height="30" ItemsSource="{Binding prPosition}" SelectedItem="{Binding SelectedClass}" DisplayMemberPath="Descript" Grid.Column="2"/>

Then:

{
    public class SchwDescr
    {
        public string Nr { get; set; }
        public string Descript{ get; set; }
        public string Kind { get; set; }
    }
}

public sealed partial class MainPage : Page, INotifyPropertyChanged
    {

    public List<SchwDescr> prMachtype { get; set; }
    public List<SchwDescr> prPosition { get; set; }

    SchwDescr _SelectedClass;

    public SchwDescr SelectedClass
        {
            get
            {
                return _SelectedClass;
            }
            set
            {
                if (_SelectedClass != value)
                {
                    _SelectedClass = value;
                    RaisePropertyChanged("SelectedClass");
                }
            }
        }

en this is the start:

public MainPage()
{
        this.InitializeComponent();
        this.LoadData(); // This returns all Lists async, like this.prMachtype etc
        DataContext = this;

What did I miss?

Upvotes: 1

Views: 464

Answers (1)

Andrew
Andrew

Reputation: 5093

You need to use IObservableCollection instead of List for prMachtype and prPosition.

Upvotes: 2

Related Questions