Reputation: 3312
I would like to know, which classes and/or interfaces can be assigned to the WPF CollectionViewSource.Source Property
. The help documentation doesn't explain anything:
public object Source { get; set; }
There is no explanation nor code sample and since Source
is of type object
, anything can be assigned. I guess Source
is supporting various interfaces as sources, but which ones ?
I know for example that it works with a List<>
, which implements a number of interfaces. I guess the most basic of them is IEnumerable<T>
. Does Source
accept anything that implements IEnumerable<T>
and the reason that Source
is of type object
is because it has to support also IEnumerable
? What else does it support ? Does it take advantage if a higher interface like IList<>
is also implemented ?
To all of you who simply cannot resist to mark a question as duplicate:
It's quite frustrating if you mark a question as duplicate and prevent any further answers, just because you have seen somewhere an answer assigning something to CollectionViewSource.Source
. There are many of them. But please note that this question does not ask just for one example, but I would like to know everything that can be assigned.
Upvotes: 2
Views: 142
Reputation: 2128
From Reference Source:
public static readonly DependencyProperty SourceProperty
= DependencyProperty.Register(
"Source",
typeof(object),
typeof(CollectionViewSource),
new FrameworkPropertyMetadata(
(object)null,
new PropertyChangedCallback(OnSourceChanged)),
new ValidateValueCallback(IsSourceValid));
Let's see how IsSourceValid is implemented:
private static bool IsSourceValid(object o)
{
return (o == null ||
o is IEnumerable ||
o is IListSource ||
o is DataSourceProvider) &&
!(o is ICollectionView);
}
Thus, valid types are:
ICollectionView is invalid source.
Upvotes: 5