1
votes

I Have a combobox with ItemsSource bound to an ObservableCollection. A RadioButton allows the user to select a mode. for each mode, a dedicated differnt list should be available in the combobox.

My Problem with using an Observablecollection is that once the public observableCollection is initialized, modifying it is only by Clear all and Add new list, item by item.

This is highly in-efficient and causes problems with validations i have on the selected item.

Can you please suggest another method which will allow me to reset the items source so that it would be refreshed in the UI without Remove/Add?

1

1 Answers

2
votes

a very basic approach:

class VM
{
  private ObservableCollection mode1;
  private ObservableCollection mode2;

    //view binds to this
  public ObservableCollection<T> X { get; private set; }

    //changing radiobutton invokes this
  public void ChangeMode( mode )
  {
    if( mode == 1 )
      X = mode1;
    else if( mode == 2 )
      X = mode2;
    else
      X = null;
  }
}

haven't tested it, but should work; if there's no update in the UI after changing mode you should call RaisePropertyChanged( ... ) for X before ChangeMode returns. Also, if you do not add/remove to the list there's no real need for an ObservableCollection, instead you can just use a List<T>