【发布时间】:2010-12-20 02:18:33
【问题描述】:
我正在编写一个 Silverlight 应用程序。我想要一个垂直显示行的列表框。然后对于每一行,该行应该有一个标题列,然后是面板的水平列表。我已经弄清楚了布局。我的问题在于数据绑定。
ListBox 被绑定到一个集合。该集合中的每个项目都将成为列表框中的一行。集合中的每个项目也都有一个集合,该集合将绑定到每个 ListBox 行内的 ItemsControl ItemsSource。
例如
[标题][x][y][z] [标题][x2][y2][z2] [标题][x3][y3][z3]
我需要使用什么绑定语法?
<ListBox Name="listRuleSteps" Height="150" Loaded="ListBox_Loaded" ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Vertical" Height="50">
<dataInput:Label Content="{Binding StepID}"></dataInput:Label>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Vertical">
<ItemsControl ItemsSource="{Binding SelectedItem.RuleEngineParts, ElementName=listRuleSteps}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<controlToolkit:WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<controlToolkit:WrapPanel Width="100">
<dataInput:Label Content="Text1"></dataInput:Label>
</controlToolkit:WrapPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我认为问题出在这条线上。我显然不想使用 SelectedItem,但我不确定要绑定 ItemsSource 的内容。
<ItemsControl ItemsSource="{Binding SelectedItem.RuleEngineParts, ElementName=listRuleSteps}" >
如果您认为我这样做的方式完全错误,请告诉我。我真的是 Silverlight 的新手。
【问题讨论】: