2010-01-27 29 views
1

我正试图创建看起来很漂亮的ListboxListBoxItem s被选中后应该扩大,但问题是,他们也应该包含另一个ListBox充满了关于特定项目的一些细节,我不知道如何将一些数据放入它。 我已经尝试从C#代码访问它并将其绑定到XAML中,但我仍然无法靠近解决方案。WPF:将数据插入放置在ListBoxItem中的列表框中

<UserControl.Resources>   
    <ResourceDictionary> 
    <DataTemplate x:Key="SelectedTemplate"> 
      <StackPanel Orientation="Vertical"> 
       <StackPanel Orientation="Horizontal"> 
        <TextBlock Text="{Binding Path = Order}" Style="{StaticResource SampleListCellItem}" MinWidth="35"/> 
        <TextBlock Text="{Binding Path = FullName}" Style="{StaticResource SampleListCellItem}" Width="340"/>      
        <TextBlock Text="{Binding Path = FirstName}" Style="{StaticResource SampleListCellItem}" Width="200" /> 
        <TextBlock Text="{Binding Path = BirthDate, StringFormat = d}" Style="{StaticResource SampleListCellItem}" Width="100"/> 
       </StackPanel> 
       <StackPanel HorizontalAlignment="Right"> 
        <ListBox Name="InnerList" Height="200" Width="200"/> 
        <Button Name="Button1" Height="40" Width="100" Content="ButtonText" Visibility="Visible"/> 
       </StackPanel> 
      </StackPanel> 
     </DataTemplate> 
     <DataTemplate x:Key="ItemTemplate"> 
      <StackPanel Orientation="Vertical"> 
       <StackPanel Orientation="Horizontal"> 
        <TextBlock Text="{Binding Path = Order}" Style="{StaticResource SampleListCellItem}" MinWidth="35"/> 
        <TextBlock Text="{Binding Path = FullName}" Style="{StaticResource SampleListCellItem}" Width="340"/> 
        <TextBlock Text="{Binding Path = FirstName}" Style="{StaticResource SampleListCellItem}" Width="200" /> 
        <TextBlock Text="{Binding Path = BirthDate, StringFormat = d}" Style="{StaticResource SampleListCellItem}" Width="100"/> 
       </StackPanel> 
      </StackPanel> 
     </DataTemplate> 

     <Style TargetType="{x:Type ListBoxItem}" x:Key="ContainerStyle"> 
      <Setter Property="ContentTemplate" Value="{StaticResource ItemTemplate}"/> 
      <Style.Triggers> 
       <Trigger Property="IsSelected" Value="True"> 
        <Setter Property="ContentTemplate" Value="{StaticResource SelectedTemplate}"/> 
       </Trigger> 
      </Style.Triggers> 
     </Style> 
    </ResourceDictionary> 
</UserControl.Resources> 

回答

0

在您想要显示的项目中,我假设您有一个属性(T)或与普通列表框项目源兼容的其他类型的属性。为了举例,将其命名为ListPr。

在您的数据模板中,添加一个listBox控件并将ItemsSource设置为{Binding Path = ListPr}。它应该像那样工作。在新的列表框中,您将能够定义另一个数据模板等等。

就像它在另一篇文章中提到的那样,在这种情况下,treeview可能就是你需要的东西。

希望有所帮助。

1

这听起来像你正在寻找的是一棵树。我认为TreeView控制将是您寻找的理想选择。

+0

谢谢你俩的回答,并对延迟回复感到抱歉。大卫的解决方案就像一个魅力。谢谢 – Seldon