0
votes

I have a ComboBox in WPF binding its ItemsSource Property to a Property returning an IEnumerable of String. The binding is just one-way. The class that contains the data for the ComboBox implements INotifyPropertyChanged Interface and calls the OnPropertyChanged(..) as soon as the Property gets updated. When I leave the ComboBox untouched the changes are correctly propagated. But as soon as the ComboBox is expanded once or a value is selected the changes in the ItemsSource Collection are no longer updated. What may be the reason for this behaviour?

Heres the XAML

<ComboBox Name="cmbSourceNames" 
          Grid.Row="0" 
          SelectedItem="{Binding Path=CurrentSource, UpdateSourceTrigger=PropertyChanged}"
          ItemsSource="{Binding Path=SourceAddresses, NotifyOnSourceUpdated=True}"/>

The DataContext is set in the code behind:

this.cmbSourceNames.DataContext = this._dpa;

And this one is the Method that triggers the change of the Property. The Method for adding the Packet is delegated to the Current Dispatcher with BeginInvoke.

private void DispatcherAddDataPacket(DataPacket dp)
{
    ObservableCollection<DataPacket> dpList;
    this._dpkts.TryGetValue(dp.SourceAddress, out dpList);
    if (dpList == null)
    {
        dpList = new ObservableCollection<DataPacket>();
        dpList.Add(dp);
        this._dpkts.Add(dp.SourceAddress, dpList);
        OnPropertyChanged("SourceAddresses");
    }
    else
    {
        dpList.Add(dp);
    }
}

The Property is giving back the Keys of the Dictionary as IEnumerable.

1
Please post the XAML.Mike Perrenoud
Post your binding code. Its better to bind selectedIndex to a property in viewmodelJasti
Made an edit with the XAML and some code snippetsBjörn Höper
@Jasti: I can imagine that but in this case it is a little bit more convenient because I may use the binding directly as the dictionary keyBjörn Höper
@Jasti: I also tried the code with the Binding to SelectedItem completely removed. But this did not change anything.Björn Höper

1 Answers

0
votes

Finally I implemented the Binding Property using an ObservableCollection tracking the keys when a new Packet gets added (so every key to the Dictionary has an equivalent in this ObservableCollection). I think it's not really a satisfying solution (because you have to keep track of both Collections independently) but it works like this.