我想绑定一个属性ObservableCollection<ObservableCollection<Location>>
列表框与ListBox的ItemTemplate反过来有一个网格的ItemTemplate。列表框中的列表框的布局似乎工作正常。但是,我的数据绑定存在问题。列表框的列表框绑定到集合的集合
对于第二层列表框ItemsSource,我尝试使用集合当前项目绑定ItemSource="{Binding /}"
并使用ItemsSource="{TemplateBinding /}"
进行绑定。我是WPF的新手,并且使用MVVM,因此我会赞赏任何提示和/或批评。
<ListBox Grid.Row="4" Width="610" Height="600" HorizontalContentAlignment="Stretch" ItemsSource="{Binding CurrentLocation.Children}">
<ListBox.ItemTemplate>
<DataTemplate>
<ListBox Width="550" Height="100" Margin="5" HorizontalContentAlignment="Stretch" ItemsSource="{Binding /}" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Margin="5" Text="Name:" />
<TextBlock Grid.Column="0" Grid.Row="1" Margin="5" Text="Description:" />
<TextBlock Grid.Column="1" Grid.Row="0" Margin="5" Text="{Binding Name}" />
<TextBlock Grid.Column="1" Grid.Row="1" Margin="5" Text="{Binding Description}" TextWrapping="Wrap" />
<Button Grid.Column="2" Grid.Row="0" Command="{Binding TODO}">
<TextBlock Text="Edit"/>
</Button>
<Button Grid.Column="2" Grid.Row="1" Command="{Binding TODO}">
<TextBlock Text="Delete"/>
</Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
为什么你需要一个包含ListBoxes的ListBox? – Bernard 2012-01-13 16:36:37