System.Windows.Data.CollectionViewSource.OnSourceChanged C# (CSharp) Method

OnSourceChanged() protected method

protected OnSourceChanged ( object oldSource, object newSource ) : void
oldSource object
newSource object
return void
		protected virtual void OnSourceChanged (object oldSource, object newSource)
		{
			if (newSource == null) {
				View = null;
			} else {
				ICollectionViewFactory factory = newSource as ICollectionViewFactory;
				if (factory != null) {
					View = factory.CreateView ();
				} else {
					ICollectionView view = null;
					if (CachedViews.TryGetValue (newSource, out view)) {
						View = view;
					} else {
						view = CollectionView.Create ((IEnumerable) newSource);
						CachedViews.Add (newSource, view);
						View = view;
					}
				}
			}

			Refresh ();
		}

Usage Example

示例#1
0
        /// <summary>
        ///     Called when SourceProperty is invalidated on "d."
        /// </summary>
        /// <param name="d">The object on which the property was invalidated.</param>
        /// <param name="e">Argument.</param>
        private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CollectionViewSource ctrl = (CollectionViewSource)d;

            ctrl.OnSourceChanged(e.OldValue, e.NewValue);
            ctrl.EnsureView();
        }