0

私はユーザーコントロールを持っています-「ControlBase」と言います。これには、「DependencyObject」から継承されたクラスObservableCollection<InheritedFromDO>である「SomeItems」プロパティがあります。 の子クラスのマークアップを作成するときに、「SomeItems」コレクションを開始したいと思います。しかし、コントロールにはかなり通常のDataContextがあり、バインディングは通常の場合に機能しますが、どういうわけか、そのマークアップでバインディングを使用することはできません。InheritedFromDO
ControlBase

次のようになります。

<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')

それを機能させる方法はありますか?

4

1 に答える 1

1

これは、コレクション内のアイテムが論理ツリーの一部ではないためです。コントロールを機能させるには、コントロールの論理的な子をカスタマイズするか、それを行うコントロールをサブクラス化する必要があります (例: ItemsControl)。

于 2009-04-28T10:34:00.783 に答える