Mihir Das
Mihir Das

Reputation: 478

WhenAnyValue is not getting called by RaisePropertyChanged

I am new to ReactiveUI along with DynamicData

Declaration

 ReadOnlyObservableCollection<Employee> itemSource;
     public ReadOnlyObservableCollection<Employee> ItemSource
     {
        get => itemSource;
     }
     SourceList<Employee> Employees = new SourceList<Employee>();

Implementation

Employees
    .Connect()
    .Sort(SortExpressionComparer<Employee>.Ascending(emp => emp.ID))
    .Bind(out itemSource)
    .ObserveOn(RxApp.MainThreadScheduler)
    .Do(_ =>
         {
              this.RaisePropertyChanged(nameof(ItemSource));
         })
    .DisposeMany()
    .Subscribe()
    .DisposeWith(disposable);

  this.WhenAnyValue(x => x.itemSource)
      .Do(_ =>
    {
        Debug.Print("Called");

    });

But whenever I am calling

Employees.Add(new Employee
  {
    Name = "Hello" + DateTime.Now.ToShortDateString(),
    ID = random.Next(1,1000)
 });

I expect it to print "Called" in debug window as this.WhenAnyValue should be called, but apparently this is not the case.

Could you please help me to understand if I am doing any mistake?

Upvotes: 0

Views: 508

Answers (1)

Mihir Das
Mihir Das

Reputation: 478

Thanks Glen. I was able to fix it by using below code

this.WhenAnyValue(x => x.itemSource.Count)
      .Do(_ =>
    {
        Debug.Print("Called");

    });

Upvotes: 1

Related Questions