我有一个用户控件 - 说“ControlBase”。它具有“SomeItems”属性,这是一个ObservableCollection<InheritedFromDO>
从InheritedFromDO
“DependencyObject”继承的类。
当我为子类创建标记时,ControlBase
我想启动“SomeItems”集合。但不知何故,我无法在该标记中使用绑定,尽管控件具有非常正常的 DataContext 并且绑定在正常情况下有效。
它看起来像这样:
<local:ControlBase
...
>
<local:ControlBase.SomeItems>
<SomeItem
DepPropertyOne={Binding Id} <!-- Does NOT work here -->
/>
<SomeItem
DepPropertyOne={Binding Name} <!-- Does NOT work here -->
/>
<local:ControlBase.SomeItems>
<Grid>
<TextBlock
Text={Binding Id} <!-- Works here -->
/>
</Grid>
</local:ControlBase>
输出说:
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Id; DataItem=null; target element is 'SomeItem' (HashCode=26965808); target property is 'DepPropertyOne' (type 'Object')
任何想法如何使它工作?