gpt4 book ai didi

wpf - 将嵌套列表框绑定(bind)到嵌套列表?

转载 作者:行者123 更新时间:2023-12-04 15:03:06 26 4
gpt4 key购买 nike

我有以下 ViewModel-Property:

public List<List<string>> Names .... //It's a dependency property

在我看来,我想要一个 ItemsControl有一个 ItemsControl :
 <ItemsControl ItemsSource="{Binding Names}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding ?????}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Label Text="{Binding ??????}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

如何绑定(bind)到 List 的项目?在上面的代码示例中,我将其标记为 ?????

最佳答案

只需使用绑定(bind)到当前绑定(bind)源:

ItemsSource="{Binding}"

请参阅下面的一些评论:

<ItemsControl ItemsSource="{Binding Names}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<! -- Here is the current binding source will be inner
List<string>
-->
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

<! -- Here is the current binding wource will be
a string value from the inner List<string>
-->
<ItemsControl.ItemTemplate>
<DataTemplate>
<Label Text="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

关于wpf - 将嵌套列表框绑定(bind)到嵌套列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8297112/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com