Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从成员数未知的列表动态构建选择列表_C#_Silverlight_Dynamic - Fatal编程技术网

C# 从成员数未知的列表动态构建选择列表

C# 从成员数未知的列表动态构建选择列表,c#,silverlight,dynamic,C#,Silverlight,Dynamic,我想做的是创建一个silevrlight弹出窗口,向用户显示图像,让他们选择下面的无线电控件,以确定他们选择了哪个选项。我有一个这样的物体: public class ConfigImage { public int ConfigID { get; set; } public string ConfigName { get; set; } public string ImagePath { get; set; } } 代码返回成员数未知的ConfigImage列表。我

我想做的是创建一个silevrlight弹出窗口,向用户显示图像,让他们选择下面的无线电控件,以确定他们选择了哪个选项。我有一个这样的物体:

 public class ConfigImage
{
    public int ConfigID { get; set; }
    public string ConfigName { get; set; }
    public string ImagePath { get; set; }
}
代码返回成员数未知的ConfigImage列表。我试图使用网格向用户显示图像,因此我根据列表中的成员数量动态添加列。我预计名单上会有2-5名成员。我遇到的问题是试图动态添加图像和无线电控件。我似乎在任何地方都找不到这样的例子。我尝试使用如下代码添加控件:

LayoutRoot.Children.Add(new Label);
但是我不知道如何在新标签控件上设置属性。我应该知道这一点,但我现在一片空白,似乎找不到这样的例子


非常感谢您的帮助

如果必须在代码中添加控件,则需要有对对象的引用,以便在其上设置属性:

Label label = new Label();
label.Content = "text";
label.Width = 10;
LayoutRoot.Children.Add(label);
或者,您可以使用初始值设定项:

LayoutRoot.Children.Add(new Label()
{
    Content = "text",
    Width = 10
});
正如BrokenGlass所说,您可能完全可以在xaml中完成这项工作

编辑:使用BrokenGlass的ItemsControl建议说明仅xaml的方法:

<ItemsControl x:Name="ConfigImagesItemsControl" ItemsSource="MyConfigImagesList">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Image Grid.Row="0" Source="{Binding ImagePath}" />
                <RadioButton Grid.Row="1" Content="{Binding ConfigName}" GroupName="ConfigImagesGroup" />
            </Grid>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

只需在Silverlight中使用任何基于列表的UI元素—这些元素将允许您将数据绑定到可在运行时更新的可观察集合,最简单的元素是—您可以在XAML中完全控制集合中的每个项所使用的标记