可能很简单的东西,但无法弄清楚,为什么我得到这个错误..对象不能转换为类型MyCustomType
Object of type 'System.Windows.Data.Binding' cannot be converted to type 'System.Collections.ObjectModel.ObservableCollection[IDATT.Infrastructure.Controls.Map.IMapLayerItem]'.
我工作的自定义控件并尝试设置可绑定属性。错误是下面XAML行:
代码段从IdattMap
public static readonly DependencyProperty LayersProperty =
DependencyProperty.Register("Layers", typeof(List<IdattMapLayer>), typeof(IdattMap), new PropertyMetadata(null));
public List<IdattMapLayer> Layers
{
get { return GetValue(LayersProperty) as List<IdattMapLayer>; }
set { this.SetValue(LayersProperty, value); }
}
代码从IdattMapLayer片段:
public class IdattMapLayer
{
public ControlTemplate ControlTemplate { get; set; }
public ObservableCollection<IMapLayerItem> MapItemsDataSource { get; set; }
public static readonly DependencyProperty MapItemsDataSourceProperty =
DependencyProperty.Register("MapItemsDataSource", typeof(ObservableCollection<IMapLayerItem>), typeof(IdattMap), new PropertyMetadata(OnMapItemsDataSourceChanged));
private static void OnMapItemsDataSourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
var control = sender as IdattMap;
if (control == null || control.MapControl == null) return;
}
}
。而MappedData势必VM,它是ObservableCollection<IMapLayerItem>
类型。
为什么期望“绑定”对象和传递可观察colllection不起作用?
你能不能也请显示'MappedData'资源的声明? – Clemens 2014-10-20 20:34:04
请参阅[this](http://stackoverflow.com/a/9128855/1136211)回答,以解释为什么使用更基本的集合类型可能更好。 – Clemens 2014-10-20 20:37:23
我修正了它..我做了什么,我让IdattMapLayer从DependencyObject继承,它现在即使与OmegaMan的接口 – katit 2014-10-20 20:38:58