I have a user control - say "ControlBase". It has "SomeItems" property, which is an ObservableCollection<InheritedFromDO>
, where InheritedFromDO
is a class inherited from "DependencyObject".
When I create markup for a child class of the ControlBase
i'd like to initiate the "SomeItems" collection. But somehow I cannot use bindings in that markup, although the control has a pretty normal DataContext and binding works in normal cases.
It looks like this:
<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>
The output says:
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')
Any ideas how to make it work?