我有一个写入控件但我遇到一些问题将CollectionViewSource绑定到我的ItemsSource属性。如果我将ObservableCollection绑定到ItemsSource属性,一切都按预期工作。由于CollectionViewSource绑定到它,我在输出中得到以下绑定错误。
错误:转换器无法将“Windows.UI.Xaml.Data.ICollectionView”类型的值转换为“IBindableIterable”类型; BindingExpression:Path ='JobView.View'DataItem ='App.ViewModel.MainViewModel'; target元素是MySpecialControl.MySpecialControl'(Name ='null'); target属性是'ItemsSource'(类型'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)
{
...
}
}
在我的XAML中,我将它绑定到CollectionViewSource.View
如何更改ItemsSource以接受ObservableCollection以及CollectionViewSource.View?
由于