1

我正在尝试创造精美的外观ListboxListBoxItems 应该在被选中后扩展,但问题是,它们还应该包含另一个ListBox填充了有关特定项目的一些详细信息,我不知道如何将一些数据放入其中。我已经尝试从 C# 代码访问它并在 XAML 中绑定它,但我仍然远离解决方案。

<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>
4

2 回答 2

1

听起来您正在寻找的是一棵树。我认为TreeView控件非常适合您正在寻找的内容。

于 2010-01-27T14:45:05.987 回答
0

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

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

就像在另一篇文章中提到的那样,在这种情况下,您可能需要一个树视图。

希望有帮助。

于 2010-01-27T14:49:36.070 回答