Last active
August 29, 2015 14:27
Sample for ReactiveProperty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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