Binding error when binding CollectionViewSource to custom ItemsSource

I have a written a control but I am having some issues binding a CollectionViewSource to my ItemsSource property. If I Bind an ObservableCollection to the ItemsSource property everything works as expected. With the CollectionViewSource bound to it I get the following binding error in the output.

Error: Converter failed to convert value of type 'Windows.UI.Xaml.Data.ICollectionView' to type 'IBindableIterable'; BindingExpression: Path='JobView.View' DataItem='App.ViewModel.MainViewModel'; target element is MySpecialControl.MySpecialControl' (Name='null'); target property is 'ItemsSource' (type 'IBindableIterable').

public sealed class MySpecialControl: Control { public IEnumerable ItemsSource { get { return (IEnumerable)GetValue(ItemsSourceProperty); } set { SetValue(ItemsSourceProperty, value); } } public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(MySpecialControl), new PropertyMetadata((IEnumerable)null, OnItemSourcePropertyChanged)); private static void OnItemSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ((MySpecialControl)sender).OnItemSourcePropertyChanged((IEnumerable) eventAgrs.OldValue, (IEnumerable)eventAgrs.NewValue); } private void OnItemSourcePropertyChanged(IEnumerable oldValue, IEnumerable newValue) { INotifyCollectionChanged oldCollectionChanged = oldValue as INotifyCollectionChanged; if (oldCollectionChanged != null) oldCollectionChanged.CollectionChanged -= ItemSource_CollectionChanged; INotifyCollectionChanged newCollectionChanged = newValue as INotifyCollectionChanged; if (newCollectionChanged != null) newCollectionChanged.CollectionChanged += ItemSource_CollectionChanged; } private void ItemSource_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { ... } }

In my XAML I have bound it to the CollectionViewSource.View

Any ideas how to change the ItemsSource to accept an ObservableCollection as well as a CollectionViewSource.View ?

Thanks

Category:c# Views:0 Time:2018-10-10

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.104 (s). 11 q(s)