示例#1
0
        private void Cleanup()
        {
            if (_weakEventListener != null)
            {
                _weakEventListener.Detach();
            }

            _weakEventListener = null;
        }
        protected virtual void OnColumnsChanged(DependencyPropertyChangedEventArgs e)
        {
            var oldColumns = e.OldValue as INotifyCollectionChanged;
            var newColumns = e.NewValue as INotifyCollectionChanged;

            if (oldColumns != null && _weakEventListener != null)
            {
                _weakEventListener.Detach();
                _weakEventListener = null;
            }
            if (newColumns != null)
            {
                _weakEventListener = new WeakEventListener <DataGridDynamicColumnsBehavior, object, NotifyCollectionChangedEventArgs>(this);
                _weakEventListener.OnEventAction  = (instance, source, eventArgs) => instance.OnColumnsCollectionChanged(source, eventArgs);
                _weakEventListener.OnDetachAction = (weakEventListener) => newColumns.CollectionChanged -= weakEventListener.OnEvent;
                newColumns.CollectionChanged     += _weakEventListener.OnEvent;
            }

            UpdateColumns();
        }