簡體   English   中英

如何將 ListBox 項綁定到用戶控件?

[英]How to bind a ListBox item to a user control?

人們經常使用類似的東西:

<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 以包含集合中的整個項目。

其語法是:

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

這將告訴數據綁定函數將每個 ListBox Item 的整個數據上下文綁定到 Index 控件中的 Item 屬性

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM