【问题标题】:AutoRefresh on DynamicData and ReactiveUIDynamicData 和 ReactiveUI 上的自动刷新
【发布时间】:2019-09-18 11:46:14
【问题描述】:

我正在尝试观察结果之一中 IsEnabled 的值何时发生变化:

SourceList<Models.Result> mySource = new SourceList<Models.Result>();
var isEnabledChangedOperation = mySource.Connect().AutoRefresh(r => r.IsEnabled).Select(_ => TestFunction());

但“r => r.IsEnabled”带有下划线并得到错误“无法将 lambda 表达式转换为类型 'TimeSpan?'因为它不是委托类型”

怎么了?

【问题讨论】:

  • 您的示例代码最后没有调用.Subscribe()。这是启动所有 rx 代码所必需的。

标签: dynamic-data reactiveui


【解决方案1】:

我怀疑您很可能没有将INotifyPropertyChanged 放在您的 Result 类中。

在我添加之前,我的示例代码出现了同样的错误。

【讨论】:

  • 谢谢。我添加并且可以编译项目。但它仍然不起作用。 var isEnabledChangedOperation = mySource .Connect() .AutoRefresh(r =&gt; r.IsEnabled) .ToCollection() .Do(x =&gt; TestFunction()); TestFunction 永远不会触发。我尝试了INotifyPropertyChangedReactiveObject,但没有任何改变
  • 您是否在 IsEnabled 设置器中调用 PropertyChanged 事件?比如:set {_isEnabled = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsEnabled)));Check out the unittest in the DynamicData source.@hooboe
【解决方案2】:

没有AutoRefresh()的解决方案:

向 Models.Result 添加和实现INotifyPropertyChangedReactiveObject 并设置:

var isEnabledChangedOperation = mySource
  .Connect()
  .WhenPropertyChanged(x => x.IsEnabled)
  .Subscribe(x => TestFunction());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多