2009-11-24 101 views
1

我在写一个Silverlight应用程序。我想要一个垂直显示行的列表框。然后对于每一行,该行应该有一个标题列,然后是一个水平的面板列表。我已经确定了布局。我的问题是数据绑定。如何绑定数据绑定ListBox.ItemTemplate中的Silverlight ItemsControl?

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真的很陌生。

回答

1

首先我不认为datainput:Label控制需要在这里简单的TextBlock与它的Text属性的绑定将没有额外的行李一样工作。

在内ItemsControl你可以简单的绑定是这样的: -

<ItemsControl ItemsSource="{Binding RuleEngineParts}" 

现在可以内TextBlock小号Text属性绑定到的什么都对象在RuleEngineParts集合中找到一个合适的物业。