【发布时间】:2014-10-02 17:45:55
【问题描述】:
在我的 C# windows phone 应用程序中,我创建了一个绑定来将字符串列表绑定到 ItemsControl。
// MyCollections is a List<string>
<ItemsControl x:Name="ContentRoot" ItemsSource="{Binding MyCollections}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding }" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
它有效。但我的问题是如何在绑定后将我自己的项目(例如“单击以添加更多”)添加到此 ItemsControl?
【问题讨论】:
-
在后面的代码中添加到 MyCollections。
-
也可以用
System.Collections.ObjectModel.ObservableCollection<string>代替List<string>。它会自动更新控件。