Exemple #1
0
            public void UnsubscribesFromCollectionChangedEvents()
            {
                var collection = new ObservableCollection <TestModel>();
                var wrapper    = new ChangeNotificationWrapper(collection);

                wrapper.UnsubscribeFromAllEvents();

                bool eventRaised = false;

                wrapper.CollectionChanged += (sender, e) => eventRaised = true;

                collection.Add(new TestModel());

                Assert.IsFalse(eventRaised);
            }
Exemple #2
0
            public void UnsubscribesFromPropertyChangedEvents()
            {
                var testModel = new TestModel();

                var wrapper = new ChangeNotificationWrapper(testModel);

                wrapper.UnsubscribeFromAllEvents();

                bool eventRaised = false;

                wrapper.PropertyChanged += (sender, e) => eventRaised = true;

                testModel.FirstName = "Geert";

                Assert.IsFalse(eventRaised);
            }
Exemple #3
0
            public void UnsubscribesFromCollectionItemPropertyChangedEvents()
            {
                var testModel  = new TestModel();
                var collection = new ObservableCollection <TestModel>(new[] { testModel });

                var wrapper = new ChangeNotificationWrapper(collection);

                wrapper.UnsubscribeFromAllEvents();

                bool eventRaised = false;

                wrapper.CollectionItemPropertyChanged += (sender, e) => eventRaised = true;

                testModel.FirstName = "Geert";

                Assert.IsFalse(eventRaised);
            }
Exemple #4
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_changeNotificationWrapper != null)
                {
                    _changeNotificationWrapper.PropertyChanged -= OnInstancePropertyChanged;
                    _changeNotificationWrapper.UnsubscribeFromAllEvents();
                    _changeNotificationWrapper = null;
                }

                foreach (var weakEventListener in _weakEventListeners)
                {
                    weakEventListener.Detach();
                }

                _weakEventListeners.Clear();
            }
        }
Exemple #5
0
        private void OnItemsSourceChanged(IEnumerable <IColorLegendItem> oldValue, IEnumerable <IColorLegendItem> newValue)
        {
            if (_changeNotificationWrapper != null)
            {
                _changeNotificationWrapper.CollectionItemPropertyChanged -= OnColorProviderPropertyChanged;
                _changeNotificationWrapper.UnsubscribeFromAllEvents();
                _changeNotificationWrapper = null;
            }

            SetCurrentValue(FilteredItemsSourceProperty, GetFilteredItems());
            SetCurrentValue(FilteredItemsIdsProperty, FilteredItemsSource?.Select(cp => cp.Id));

            if (newValue != null)
            {
                _changeNotificationWrapper = new ChangeNotificationWrapper(newValue);
                _changeNotificationWrapper.CollectionItemPropertyChanged += OnColorProviderPropertyChanged;
            }

            UpdateIsAllVisible();
        }
        private void OnItemsSourceChanged(IEnumerable <IColorProvider> oldValue, IEnumerable <IColorProvider> newValue)
        {
            if (_changeNotificationWrapper != null)
            {
                _changeNotificationWrapper.CollectionItemPropertyChanged -= OnColorProviderPropertyChanged;
                _changeNotificationWrapper.UnsubscribeFromAllEvents();
                _changeNotificationWrapper = null;
            }

            FilteredItemsSource = GetFilteredItems();
            FilteredItemsIds    = FilteredItemsSource == null ? null : FilteredItemsSource.Select(cp => cp.Id);

            if (newValue != null)
            {
                _changeNotificationWrapper = new ChangeNotificationWrapper(newValue);
                _changeNotificationWrapper.CollectionItemPropertyChanged += OnColorProviderPropertyChanged;
            }

            UpdateIsAllVisible();
        }