使用foreach字符串列表中的itemscontrol

时间:2018-02-14 15:55:12

标签: c# wpf foreach itemscontrol

您好我试图做一个foreach循环,它将创建一个带有图像,文本块和2个按钮作为另一个itemscontrol的子项的itemscontrol。我希望将textblock的textblock.text作为循环中的字符串。

example

的Xaml:

<Grid>
    <ItemsControl x:Name="MainControl" Margin="0,175,0,22">
        <ItemsControl Margin="10,0,0,0" Style="{StaticResource HorizontalItemsControl}">
            <Border Background="Black" BorderBrush="#FF1EF3F3" BorderThickness="2">
                <Image  Height="50" Width="50" Source="{StaticResource SoulsRebornFlame}"/>
            </Border>
            <TextBlock VerticalAlignment="Center" x:Name="PendingUsername" FontSize="18" Text="Username" FontFamily="Segoe UI Black" Margin="15,0,0,0" Foreground="White"/>

            <Button Margin="15,0,0,0" Style="{StaticResource MyButtonStyle}">
                <TextBlock VerticalAlignment="Center" FontSize="18" Text="V" FontFamily="Segoe UI Black" Foreground="Lime"/>
            </Button>
            <Button Margin="15,0,0,0" Style="{StaticResource MyButtonStyle}">
                <TextBlock VerticalAlignment="Center" FontSize="18" Text="X" FontFamily="Segoe UI Black" Foreground="Red"/>
            </Button>
        </ItemsControl>
    </ItemsControl>
</Grid>

C#

foreach(string senderusername in dataCollection)
        {
            //Create new itemscontrol with the childs and set the textblock.text equal to snederusername.
        }

所以我想以编程方式将xaml对象foreach string作为列表dataColletion。

我该怎么做? 提前谢谢。

0 个答案:

没有答案