C# - WPF - 显示字符串列表

问题描述 投票:0回答:1

当我在 xaml WPF 中搜索 foreach 的等效项时,我得到了 ItemControl 教程,但它只是关于演示文稿

它没有解决它的迭代部分

如何在 WPF 中执行此操作???

<TextBox Text ={Binding someArray[0]}/>
<TextBox Text ={Binding someArray[1]}/>
<TextBox Text ={Binding someArray[2]}/>
<TextBox Text ={Binding someArray[3]}/>
...

但动态,作为一个循环,在模板内部,没有代码隐藏

不敢相信没有教程可以完成如此简单的用例

感谢您对此的帮助

c# wpf iteration
1个回答
0
投票

我找到了这样的解决方案

<ItemsControl ItemsSource="{Binding someArray}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Text="{Binding .}"></TextBlock>
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>
© www.soinside.com 2019 - 2024. All rights reserved.