安装
Install-Package ReactiveUI
订阅属性变化
this.WhenAnyValue(x => x.Keyword)
.Throttle(TimeSpan.FromMilliseconds(500))
.Subscribe(newValue =>
{
OnRefresh();
});
this.WhenAnyPropertyChanged(nameof(ProjectStatus), nameof(Situation))
.Subscribe(s => IsChanged = true);
this.WhenPropertyChanged(s => s.OrderType).Subscribe(s => OnRefresh());
this.WhenAnyPropertyChanged(nameof(OrderType), nameof(SelectedGroup)).Subscribe(s => OnRefresh());
public int Total { [ObservableAsProperty] get; }
public IEnumerable<UrlInfo> Items { [ObservableAsProperty] get; }
this.WhenAnyValue(x => x.AllItems, x => x.Keyword, (items, keyword) =>
{
if (items.IsNullOrEmpty())
return null;
if (keyword.IsNullOrEmpty())
{
return items;
}
else
{
var cmp = StringComparison.CurrentCultureIgnoreCase;
return items.Where(s => s.Name.Contains(keyword, cmp) || s.Url.Contains(keyword, cmp));
}
}).Throttle(TimeSpan.FromMilliseconds(500)).ToPropertyEx(this, x => x.Items);
this.WhenAnyValue(x => x.Items, s => s?.Count() ?? 0).ToPropertyEx(this, x => x.Total);