8

人々は次のようなものを頻繁に使用します。

<ListBox ItemsSource="{Binding ElementName=thisControl, Path=ListIndexes}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Label Content="{Binding Path=IndexName}"/>
<Label Content="{Binding Path=IndexValue}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

しかし、ラベルの代わりに、次のようなコントロールを使用したいと思います。

<ListBox ItemsSource="{Binding ElementName=thisControl, Path=ListIndexes}">
<ListBox.ItemTemplate>
<DataTemplate>
<local:Index Item="**{Binding}**"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

コレクションのアイテム全体を含めるために、この Binding に何を入れるかは疑問です。

4

1 に答える 1

15

この構文は次のとおりです。

<local:Index Item="{Binding}"/>

これにより、データ バインディング関数は、各 ListBox アイテムのデータ コンテキスト全体を Index コントロールの Item プロパティにバインドするように指示されます。

于 2009-01-26T13:11:48.087 に答える