-1

I use the following dictionary:

private Dictionary<string, string> _myDic;
public Dictionary<string, string> MyDic
{
   get
   {
       return _myDic;
   }
   set
   {
      if (_myDic!= value)
      {
         _myDic= value;
         NotifyPropertyChanged("MyDic");
      }
    }
}

Is bind to a combobox in my view.

Everything works.

The problem is that when I add item is not updated if already opened the combobox.

Only if it remains closed from the beginning then the change appears on the screen.

I have a single place where I add item to dictionary and immediately I used the event propertychanged hoping it will affect the UI:

MyDic.Add(strK, strV);
NotifyPropertyChanged("MyDic");

But it did not help (although the event did not coming null).

I understand that it is because it is a change in the collection, not the object itself. My problem is that I can not change the type of this variable to cutsom ObservableDictionary for various reasons.

My question is why the NotifyPropertyChanged("MyDic"); is not affected. And is there any other way (except to change the type) to deal with this problem?

Hodaya Shalom
  • 4,327
  • 12
  • 57
  • 111

1 Answers1

0

I found a way a bit primitive. And yet it worked.

I created another dictionary which I added the item to it.

Then I changed my dictionary to the local dictionary:

Dictionary<string, string> _dic = new Dictionary<string, string>();
foreach (var str in MyDic)
   _dic.Add(str.Key, str.Value);
 _dic.Add(strK, strV);
  MyDic= _dic; 

If someone has a better way I'd love to hear.

Hodaya Shalom
  • 4,327
  • 12
  • 57
  • 111