gpt4 book ai didi

c# - WPF 绑定(bind) ItemsControl 中的字符串值列表

转载 作者:行者123 更新时间:2023-11-30 19:38:06 24 4
gpt4 key购买 nike

我有以下模型类

 ResultViewModel
public string word {get;set;}
public List<string> meanings {get;set;}

具有 2 个属性。如何将含义列表字符串绑定(bind)到堆栈面板?

我的数据会像

word="a", meanings= "a1","a2","a3"

word="b", meanings= "b1","b2","b3"...

word="c", meanings= "c1","c2","c3"...

我有以下 xaml 可以帮助我绑定(bind)“a”“b”“c”等但现在我想在其底部显示含义

    <ItemsControl Name="lviewLookupResult"  Background="#363636">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="5 5 5 0">
<Label Margin="5 0" Padding="0" Content="{Binding word}" />
</StackPanel>
<StackPanel Orientation="Vertical" Margin="5 5 5 0">

??????HOW CAN I SHOW Meanings HERE???????????


</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

我正在使用下面的代码绑定(bind)模型并且绑定(bind)在运行时没问题

  List<ResultViewModel> view_model = new List<ResultViewModel>();           
lviewLookupResult.ItemsSource = view_model;

最佳答案

像这样使用另一个 ItemsControl:

   <ItemsControl Name="lviewLookupResult"  Background="#363636">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" Margin="5 5 5 0">
<Label Margin="5 0" Padding="0" Content="{Binding word}" />
</StackPanel>
<ItemsControl Margin="5 5 5 0" ItemsSource="{Binding meanings}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

关于c# - WPF 绑定(bind) ItemsControl 中的字符串值列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35079896/

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