C# 如何绑定列表<;字符串>;到ItemsControl?
在我的演示者中,我具有以下属性:C# 如何绑定列表<;字符串>;到ItemsControl?,c#,wpf,xaml,itemscontrol,C#,Wpf,Xaml,Itemscontrol,在我的演示者中,我具有以下属性: public List<string> PropertyNames { get; set; } 公共列表属性名称{get;set;} 我想用ItemsControl/DataTemplate列出名称,如下所示: <ItemsControl ItemsSource="{Binding PropertyNames}"> <ItemsControl.ItemTemplate> <DataTempla
public List<string> PropertyNames { get; set; }
公共列表属性名称{get;set;}
我想用ItemsControl/DataTemplate列出名称,如下所示:
<ItemsControl ItemsSource="{Binding PropertyNames}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Value}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
由于泛型列表没有命名属性,我如何在绑定语句中引用值呢?让我回答这个问题,这只是
{Binding}
完成相同任务的更简单方法是使用:
<ItemsControl ItemsSource="{Binding PropertyNames}"/>
默认情况下,这将创建一个垂直堆栈面板,并将每个元素添加到其自己的文本块中。根据,这适用于以下任何情况:
- 一串
- 日期时间对象
- UIElement对象
- 包含椭圆和文本块的面板控件