我在我的代码后面绑定到ItemsControl:
I bind to a ItemsControl in my codebehind:
ColumnVisibilityItems.DataContext = gc.ColumnVisibility;其中ColumnVisibility是ObservableCollection,也使用字典对其进行了尝试.
where ColumnVisibility is a ObservableCollection, also tried it with dictionary..
我的标记
<ItemsControl x:Name="ColumnVisibilityItems"> <Label Content="{Binding Path=Name}" /> </ItemsControl>单步执行过程中,我看到集合绑定中包含11个项目.但是ItemsControl仅呈现集合中的第一个项目.
while stepping through, i see the collection bound having 11 items. but ItemsControl renders only the first item in collection.
是否需要设置ItemsSource属性才能使其正常工作?因为每当我尝试在后面的代码中设置它时,我都会得到一个例外,说项目无法修改,因为它们已经存在.
Is ItemsSource property necessary to be set for this to work? because whenever i try to set that in code behind, i get the exception saying items cannot be modified because they exist already.
推荐答案基本上,您需要指定模板.有关完整示例,请参见 msdn文档
basically you need to specify your Template. See the msdn docs for a fuller example
<ItemsControl x:Name="ColumnVisibilityItems" ItemsSource="{Binding}> <ItemsControl.ItemTemplate> <DataTemplate> <Label Content="{Binding Path=Name}" /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>更多推荐
wpf ItemsControl绑定问题
发布评论