Availability ObservableCollection Update Launch

So I have something in the lines

private  ObservableCollection<ViewModel> _internal;

public ObservableCollection<ViewModel> BoundInternal{get;set}; //this is Binded in the Itemssource like ItemSource={Binding BoundInternal}

Now in my code I am doing something like

BoundInternal = _internal, however, the problem is that BoundInternal does not fire the collectionChanged event. I need to use the Add method. So I wonder if there is a solution for this.

+3
source share
2 answers

Here is what I suspect your code should look like (although this is not quite what you are doing now): -

public class YourClassHoldingThisStuff : INotifyProperyChanged
{
  private  ObservableCollection<ViewModel> _internal;

  public ObservableCollection<ViewModel> BoundInternal
  {
    get { return _internal; }
    set
    {
      _internal = value;
      NotifyPropertyChanged("BoundInternal");
    };
  }
  public event PropertyChangedEventHandler PropertyChanged;

  private void NotifyPropertyChanged(string name)
  {
    if (PropertyChanged != null)
      PropertyChanged(this, new ProperytChangedEventArgs(name));
  }
}

_internal BoundInternal, BoundInternal ( _internal). , .

- _internal BoundInternal, : -

public class YourClassHoldingThisStuff : INotifyProperyChanged
{
  private  ObservableCollection<ViewModel> _internal;
  private  ObservableCollection<ViewModel> _boundInternal;

  public ObservableCollection<ViewModel> BoundInternal
  {
    get { return _boundInternal; }
    set
    {
      _boundInternal = value;
      NotifyPropertyChanged("BoundInternal");
    };
  }
  public event PropertyChangedEventHandler PropertyChanged;

  private void NotifyPropertyChanged(string name)
  {
    if (PropertyChanged != null)
      PropertyChanged(this, new ProperytChangedEventArgs(name));
  }
}

- , BoundInternal = _internal, .

+4

ItemsControl Items, Refresh(), , .

MyList.Items.Refresh()

+2

Source: https://habr.com/ru/post/1740625/


All Articles