private void OnCollectionChanged(object oldValue, object newValue)
        {
            if (oldValue is INotifyCollectionChanged)
            {
                var incc = (INotifyCollectionChanged)oldValue;
                incc.CollectionChanged -= Incc_CollectionChanged;
                _inccWeakEventListener?.Detach();
                _inccWeakEventListener = null;
            }

            if (newValue is IEnumerable)
            {
                if (newValue is INotifyCollectionChanged)
                {
                    var incc = (INotifyCollectionChanged)newValue;
                    _inccWeakEventListener = new WeakEventListener <RotatorTile, object, NotifyCollectionChangedEventArgs>(this)
                    {
                        OnEventAction  = (instance, source, eventArgs) => instance.Incc_CollectionChanged(source, eventArgs),
                        OnDetachAction = (listener) => incc.CollectionChanged -= listener.OnEvent
                    };
                    incc.CollectionChanged += _inccWeakEventListener.OnEvent;
                }

                Start();
            }
            else
            {
                _timer?.Stop();
            }
        }
        /// <summary>
        /// Handles changes to the ItemsSource property.
        /// </summary>
        /// <param name="oldValue">Old value.</param>
        /// <param name="newValue">New value.</param>
        private void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
        {
            // Remove handler for oldValue.CollectionChanged (if present)
            INotifyCollectionChanged oldValueINotifyCollectionChanged = oldValue as INotifyCollectionChanged;

            if (null != oldValueINotifyCollectionChanged)
            {
                // Detach the WeakEventListener
                if (null != _weakEventListener)
                {
                    _weakEventListener.Detach();
                    _weakEventListener = null;
                }
            }

            // Add handler for newValue.CollectionChanged (if possible)
            INotifyCollectionChanged newValueINotifyCollectionChanged = newValue as INotifyCollectionChanged;

            if (null != newValueINotifyCollectionChanged)
            {
                // Use a WeakEventListener so that the backwards reference doesn't keep this object alive
                _weakEventListener = new WeakEventListener <SeriesDefinition, object, NotifyCollectionChangedEventArgs>(this);
                _weakEventListener.OnEventAction  = (instance, source, eventArgs) => instance.ItemsSourceCollectionChanged(source, eventArgs);
                _weakEventListener.OnDetachAction = (weakEventListener) => newValueINotifyCollectionChanged.CollectionChanged -= weakEventListener.OnEvent;
                newValueINotifyCollectionChanged.CollectionChanged += _weakEventListener.OnEvent;
            }

            if (null != ParentDefinitionSeries)
            {
                ParentDefinitionSeries.SeriesDefinitionItemsSourceChanged(this, oldValue, newValue);
            }
        }
        private void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
        {
            // Remove handler for oldValue.CollectionChanged (if present)
            INotifyCollectionChanged oldValueINotifyCollectionChanged = oldValue as INotifyCollectionChanged;

            if (null != oldValueINotifyCollectionChanged && null != _collectionChangedWeakEventListener)
            {
                _collectionChangedWeakEventListener.Detach();
                _collectionChangedWeakEventListener = null;
            }

            // Add handler for newValue.CollectionChanged (if possible)
            INotifyCollectionChanged newValueINotifyCollectionChanged = newValue as INotifyCollectionChanged;

            if (null != newValueINotifyCollectionChanged)
            {
                _collectionChangedWeakEventListener = new WeakEventListener <MultiCircleChart, object, NotifyCollectionChangedEventArgs>(this);
                _collectionChangedWeakEventListener.OnEventAction   = (instance, source, eventArgs) => instance.ItemsSourceCollectionChanged(source, eventArgs);
                _collectionChangedWeakEventListener.OnDetachAction  = (weakEventListener) => newValueINotifyCollectionChanged.CollectionChanged -= weakEventListener.OnEvent;
                newValueINotifyCollectionChanged.CollectionChanged += _collectionChangedWeakEventListener.OnEvent;
            }

            // Store a local cached copy of the data
            _items = newValue == null ? null : new List <object>(newValue.Cast <object>().ToList());

            //// Clear and set the view on the selection adapter
            RefreshView();
        }
 private void UnregisterSelectedStopsSourceHandlers(ObservableCollection <TransitStop> collection)
 {
     if (SelectedStopsSource_CollectionChanged_Listener != null)
     {
         SelectedStopsSource_CollectionChanged_Listener.Detach();
         SelectedStopsSource_CollectionChanged_Listener = null;
     }
 }
 private void UnregisterStopsSourceHandlers(ObservableCollection <TransitStop> collection)
 {
     if (StopsSource_CollectionChanged_Listener != null)
     {
         collection.CollectionChanged -= StopsSource_CollectionChanged_Listener.OnEvent;
         StopsSource_CollectionChanged_Listener?.Detach();
         StopsSource_CollectionChanged_Listener = null;
     }
 }
Beispiel #6
0
        public void RaiseWeakReferenceEvents()
        {
            bool        isOnEventTriggered  = false;
            bool        isOnDetachTriggered = false;
            SampleClass sample = new SampleClass();
            WeakEventListener <SampleClass, object, EventArgs> weak = new WeakEventListener <SampleClass, object, EventArgs>(sample);

            weak.OnEventAction  = (instance, source, eventArgs) => { isOnEventTriggered = true; };
            weak.OnDetachAction = (listener) => { isOnDetachTriggered = true; };
            sample.RaiseEvent  += weak.OnEvent;
            sample.DoSomething();
            Debug.Assert(isOnEventTriggered);
            weak.Detach();
            Debug.Assert(isOnDetachTriggered);
        }
Beispiel #7
0
        internal void UnWireEvents(IEnumerable value)
        {
            INotifyCollectionChanged notifyingDataSource1 = value as INotifyCollectionChanged;

            if (notifyingDataSource1 != null && _weakCollectionChangedListener != null)
            {
                _weakCollectionChangedListener.Detach();
                _weakCollectionChangedListener = null;
            }

            IObservableVector <object> notifyingDataSource2 = value as IObservableVector <object>;

            if (notifyingDataSource2 != null && _weakVectorChangedListener != null)
            {
                _weakVectorChangedListener.Detach();
                _weakVectorChangedListener = null;
            }

#if FEATURE_ICOLLECTIONVIEW_SORT
            if (this.SortDescriptions != null && _weakSortDescriptionsCollectionChangedListener != null)
            {
                _weakSortDescriptionsCollectionChangedListener.Detach();
                _weakSortDescriptionsCollectionChangedListener = null;
            }
#endif

            if (this.CollectionView != null)
            {
                if (_weakCurrentChangedListener != null)
                {
                    _weakCurrentChangedListener.Detach();
                    _weakCurrentChangedListener = null;
                }

                if (_weakCurrentChangingListener != null)
                {
                    _weakCurrentChangingListener.Detach();
                    _weakCurrentChangingListener = null;
                }
            }

            this.EventsWired = false;
        }
Beispiel #8
0
        private void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
        {
            OnPause();
            _isItemsUpdate = true;
            AnimationIndex = 0;
            // Remove handler for oldValue.CollectionChanged (if present)
            INotifyCollectionChanged oldValueINotifyCollectionChanged = oldValue as INotifyCollectionChanged;

            if (null != oldValueINotifyCollectionChanged && null != _collectionChangedWeakEventListener)
            {
                _collectionChangedWeakEventListener.Detach();
                _collectionChangedWeakEventListener = null;
            }

            // Add handler for newValue.CollectionChanged (if possible)
            INotifyCollectionChanged newValueINotifyCollectionChanged = newValue as INotifyCollectionChanged;

            if (null != newValueINotifyCollectionChanged)
            {
                _collectionChangedWeakEventListener = new WeakEventListener <NewsFlowList, object, NotifyCollectionChangedEventArgs>(this);
                _collectionChangedWeakEventListener.OnEventAction   = (instance, source, eventArgs) => instance.ItemsSourceCollectionChanged(source, eventArgs);
                _collectionChangedWeakEventListener.OnDetachAction  = (weakEventListener) => newValueINotifyCollectionChanged.CollectionChanged -= weakEventListener.OnEvent;
                newValueINotifyCollectionChanged.CollectionChanged += _collectionChangedWeakEventListener.OnEvent;
            }

            // Store a local cached copy of the data
            _items = newValue == null ? null : new List <object>(newValue.Cast <object>().ToList());

            // Clear and set the view on the selection adapter
            ClearView();
            if (_listSelector != null && _listSelector.ItemsSource != _view)
            {
                _listSelector.ItemsSource = _view;
            }
            RefreshView();
            OnResume();
            if (_animateTimer == null && AutoPlay)
            {
                Animate();
            }
        }
        private static void HandleItemSelectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var behavior = d as BindSelectedItemsBehavior;

            if (desiredSelectionChangedEventListener != null)
            {
                desiredSelectionChangedEventListener.Detach();
            }

            if (e.NewValue != null)
            {
                var itemSelection = (e.NewValue as ItemSelection);

                desiredSelectionChangedEventListener = new WeakEventListener <BindSelectedItemsBehavior, object, DesiredSelectionChangedEventArgs>(
                    behavior)
                {
                    OnDetachAction = (l => itemSelection.DesiredSelectionChanged -= l.OnEvent),
                    OnEventAction  = (b, s, eventArgs) => b.HandleDesiredSelectionChanged(s, eventArgs)
                };

                itemSelection.DesiredSelectionChanged += desiredSelectionChangedEventListener.OnEvent;
            }
        }
Beispiel #10
0
        private void UpdateIncrementalItemsSource()
        {
            if (_weakIncrementalItemsSourcePropertyChangedListener != null)
            {
                _weakIncrementalItemsSourcePropertyChangedListener.Detach();
                _weakIncrementalItemsSourcePropertyChangedListener = null;
            }

            // Determine if incremental loading should be used
            if (_dataSource is ISupportIncrementalLoading incrementalDataSource)
            {
                _incrementalItemsSource = incrementalDataSource;
            }
            else if (_owner.ItemsSource is ISupportIncrementalLoading incrementalItemsSource)
            {
                _incrementalItemsSource = incrementalItemsSource;
            }
            else
            {
                _incrementalItemsSource = default(ISupportIncrementalLoading);
            }

            if (_incrementalItemsSource != null && _incrementalItemsSource is INotifyPropertyChanged inpc)
            {
                _weakIncrementalItemsSourcePropertyChangedListener = new WeakEventListener <DataGridDataConnection, object, PropertyChangedEventArgs>(this);
                _weakIncrementalItemsSourcePropertyChangedListener.OnEventAction  = (instance, source, eventArgs) => instance.NotifyingIncrementalItemsSource(source, eventArgs);
                _weakIncrementalItemsSourcePropertyChangedListener.OnDetachAction = (weakEventListener) => inpc.PropertyChanged -= weakEventListener.OnEvent;
                inpc.PropertyChanged += _weakIncrementalItemsSourcePropertyChangedListener.OnEvent;
            }

            if (_loadingOperation != null)
            {
                _loadingOperation.Cancel();
                _loadingOperation = null;
            }
        }
Beispiel #11
0
        public void OpenShareMessagePicker(string link, Action <PickDialogEventArgs> callback = null)
        {
            var isVisible             = false;
            var frame                 = Application.Current.RootVisual as PhoneApplicationFrame;
            PhoneApplicationPage page = null;

            if (frame != null)
            {
                page = frame.Content as PhoneApplicationPage;
                if (page != null)
                {
                    page.IsHitTestVisible = false;
                    var applicationBar = page.ApplicationBar;
                    if (applicationBar != null)
                    {
                        isVisible = applicationBar.IsVisible;
                        applicationBar.IsVisible = false;
                    }
                }

                var weakEventListener = new WeakEventListener <ProxyView, object, NavigatingCancelEventArgs>(this, frame);
                frame.Navigating += weakEventListener.OnEvent;

                weakEventListener.OnEventAction = (view, o, args) =>
                {
                    view.Frame_Navigating(o, args);
                };
                weakEventListener.OnDetachAction = (listener, source) =>
                {
                    var f = source as PhoneApplicationFrame;
                    if (f != null)
                    {
                        f.Navigating -= listener.OnEvent;
                    }
                };

                _weakEventListener = weakEventListener;
            }

            if (page == null)
            {
                return;
            }

            var popup       = new Popup();
            var sharePicker = new ShareMessagePicker
            {
                Width  = page.ActualWidth,
                Height = page.ActualHeight,
                Link   = link
            };

            _shareMessagePicker = sharePicker;
            page.SizeChanged   += Page_SizeChanged;

            sharePicker.Close += (sender, args) =>
            {
                _shareMessagePicker = null;
                _weakEventListener.Detach();
                _weakEventListener = null;

                popup.IsOpen = false;
                popup.Child  = null;

                frame = Application.Current.RootVisual as PhoneApplicationFrame;
                if (frame != null)
                {
                    page = frame.Content as PhoneApplicationPage;
                    if (page != null)
                    {
                        page.SizeChanged     -= Page_SizeChanged;
                        page.IsHitTestVisible = true;
                        var applicationBar = page.ApplicationBar;
                        if (applicationBar != null)
                        {
                            applicationBar.IsVisible = isVisible;
                        }
                    }
                }
            };
            _shareMessagePicker.Pick += (sender, args) =>
            {
                callback.SafeInvoke(args);
            };

            popup.Child  = sharePicker;
            popup.IsOpen = true;
        }