如何将List <string>绑定到ItemsControl?

Edw*_*uay 13 c# wpf xaml itemscontrol

在我的演示者中,我有这个属性:

public List<string> PropertyNames { get; set; }
Run Code Online (Sandbox Code Playgroud)

我想用ItemsControl/DataTemplate列出名称,如下所示:

<ItemsControl ItemsSource="{Binding PropertyNames}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Value}"/>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)

由于通用列表没有命名属性,如何在Binding语句中引用该

Edw*_*uay 36

让我回答一下,这只是{Binding}.

  • 仅供参考,'.' 可以使用或不使用"Path =".空白被隐式解释为'.'.所以你可以写{Binding},{Binding.}或{Binding Path =.}注意{Binding Path =}不起作用 - 你会得到一个XAML编译器错误. (11认同)
  • 哈哈.问题在11:15被问到,并在一分钟之后由完全相同的人回答.然后接受答案:)干得好. (3认同)