我正试图创建看起来很漂亮的Listbox
。 ListBoxItem
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>
谢谢你俩的回答,并对延迟回复感到抱歉。大卫的解决方案就像一个魅力。谢谢 – Seldon