0

I have a listview in my Xaml which is bound to ActiveList property in my data model.

Based on what gets selected I want to change the contents of the list to another list. If I debug through the viewmodel, I can see the list is being assigned the new list just fine, but this isn't being reflected in the UI!

The lists are ObservableCollections which implement the INotifyCollectionChanged interface. So why isn't the UI being refreshed?

Viewmodel:

public TcgType SelectedTcgType
        {
            get { return _selectedTcgType; }
            set
            {
                Set(ref _selectedTcgType, value);
                switch (value.Name)
                {
                    case "Yugioh":
                        ActiveCards = YugiohCards;
                        break;

                    case "Hearthstone":
                        ActiveCards = HearthStoneCards;
                        break;
                    case "DBZ":
                        ActiveCards = DbzCards;
                        break;
                    case "Pokemon":
                        ActiveCards = PokemonCards;
                        break;

                }

                //Set(ref _selectedTcgType, value);
            }
        }

Set function:

public bool Set<T>(ref T field, T value,
            [CallerMemberName] string propertyName = null)
        {
            if (EqualityComparer<T>.Default.Equals(field, value))
                return false;

            field = value;
            RaisepropertyChanged(propertyName);
            return true;
        }
Clemens
  • 123,504
  • 12
  • 155
  • 268
magna_nz
  • 1,243
  • 5
  • 23
  • 42
  • Maybe you need [ObservableCollectionEx](http://stackoverflow.com/questions/269073/observablecollection-that-also-monitors-changes-on-the-elements-in-collection) – Lei Yang Nov 22 '16 at 01:38

1 Answers1

0

Based on my Set Method, the I wasn't raising the Property event changed for the collection. Only for the selected value in the listview.

I added a RaisePropertyChanged("ActiveList") from my switch statement and it updated.

 protected void RaisepropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
magna_nz
  • 1,243
  • 5
  • 23
  • 42