Пример #1
0
        public PersonContext(PopulationContext population)
        {
            _fullName = this
                        .WhenAnyValue(x => x.FirstName, x => x.LastName,
                                      (firstName, lastName) => $"{firstName} {lastName}")
                        .ToProperty(this, x => x.FullName);

            _bestFriendName = this
                              .WhenAnyValue(x => x.BestFriend)
                              .Select(bf => bf == null
                    ? Observable.Return("I don't have a best friend")
                    : bf.WhenAnyValue(f => f.FullName).Select(fn => $"{fn} is my best friend."))
                              .Switch()
                              .ToProperty(this, x => x.BestFriendName);

            _itemsRemovedSubscription = population.People.BeforeItemsRemoved
                                        .Do(p => Console.WriteLine($@"{FullName} => Person removed {p?.FullName}"))
                                        .Where(p => p == BestFriend)
                                        .Select(p => (PersonContext)null)
                                        .BindTo(this, x => x.BestFriend);
        }
Пример #2
0
        public MainWindow()
        {
            InitializeComponent();

            DataContext = new PopulationContext();
        }