Reactive Extensions for .NET (Rx) in WPF - MVVM

后端 未结 1 1154
萌比男神i
萌比男神i 2020-12-28 10:20

I am using Reactive extensions for NET (Rx) with Caliburn.Micro in my WPF app. I\'m trying to port my WPF app to use an MVVM architecture and I need to monitor changes in th

1条回答
  •  半阙折子戏
    2020-12-28 10:31

    Add a Nick property to your ViewModel and implement INotifyPropertyChanged. Then you can do this

    Observable.FromEventPattern(this, "PropertyChanged")
              .Where(e => e.EventArgs.PropertyName == "Nick")
              .Select(_ => this.Nick)
              .Where(text => text.Length > 3)
              //Subscribe will call LoadUser, no need for the extra Do(...)
              .Throttle(TimeSpan.FromSeconds(3000))
              .Subscribe(LoadUser);  
    

    and then your XAML would be something like this

    
    

    0 讨论(0)
提交回复
热议问题