Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.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# 如何绑定列表<;字符串>;到ItemsControl?_C#_Wpf_Xaml_Itemscontrol - Fatal编程技术网

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对象
  • 包含椭圆和文本块的面板控件

FYI,“.”可使用或不使用“路径=”。Blank被隐式解释为“.”。因此,您可以编写{Binding}、{Binding.}或{Binding Path=.}。请注意,{Binding Path=}不起作用-您将得到一个XAML编译器错误。哈哈。问题在11点15分提出,一分钟后由完全相同的人回答。然后答案被接受:)干得好。