Пример #1
0
        /// <summary>
        /// Setup the Options based on the OptionsString and the Value string.
        /// It tracks changes and updates the collection accordingly.
        /// </summary>
        /// <param name="notifyPropertyChanged">Whether or not to trigger a property changed on "Options"</param>
        public void SetOptions(bool notifyPropertyChanged = true)
        {
            var options = GetOptions(OptionsString, Value, this);
            var result = new ObservableCollection<Option>(options);

            _options = result;

            //Track changes to the Options and update the Options strings
            if (_optionsStringTracker != null)
                _optionsStringTracker.Dispose();

            _optionsStringTracker = _options.FromCollectionChangedAndNow().SelectLatest(ops =>
                //whenever an option's property changes
                       _options.Select(o => o.FromAnyPropertyChanged()).Merge().AsGeneric()
                           //whenever the collection changes
                       .AndNow()).Synchronize()
#if SILVERLIGHT
                       .ObserveOnDispatcher()
#endif

.Subscribe(_ => SyncOptionStrings());

            if (notifyPropertyChanged)
                this.CompositeRaiseEntityPropertyChanged("Options");
        }