Skip to content

Instantly share code, notes, and snippets.

@emoacht
Last active August 29, 2015 14:27
Sample for ReactiveProperty
public class MainWindowViewModel : BindableBase
{
public ObservableCollection<MemberViewModel> Members { get; } = new ObservableCollection<MemberViewModel>();
public ReactiveProperty<bool> IsAllLong { get; }
public MainWindowViewModel()
{
// Observe if all MemberViewModels pass filter delegate for CLR property.
IsAllLong = Members
.ObserveElementProperty(x => x.IsLong) // Select CLR property to be observed.
.Select(_ => Members.All(x => x.IsLong)) // Go through MemberViewModels by filter delegate.
.ToReactiveProperty();
// Alternative
IFilteredReadOnlyObservableCollection<MemberViewModel> membersNotLong = Members
.ToFilteredReadOnlyObservableCollection(x => !x.IsLong); // Provide filter delegate.
IsAllLong = membersNotLong
.CollectionChangedAsObservable()
.Select(_ => Members.Any() && (0 == membersNotLong.Count))
.ToReactiveProperty();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment