【发布时间】:2023-03-11 00:41:01
【问题描述】:
我在另一个列表框的 dataTemplate 中有一个列表框。我可以获取外部列表框的选定项,但我一直试图获取内部列表框的选定项(名称:“ListBoxLetter”),没办法..
这是我的 xaml:
<ListBox x:Name="ListBoxOut" ItemsSource="{Binding Letters}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Width="500" Height="60" Background="#16C8DB">
<TextBlock Text="{Binding Date}" />
</StackPanel>
<ListBox x:Name="ListBoxLetter" ItemsSource="{Binding CourriersListe}" SelectedItem="{Binding Selection, Mode=TwoWay}" >
<Interactivity:Interaction.Triggers>
<Interactivity:EventTrigger EventName="SelectionChanged" >
<Command:EventToCommand Command="{Binding SelectionCommand}" CommandParameter="{Binding Selection}" />
</Interactivity:EventTrigger>
</Interactivity:Interaction.Triggers>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Date}" />
<TextBlock Text="{Binding Name}"/>
</StackPanel>
<TextBlock Text="{Binding Title}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>`
“Courriers”是以下类的对象:
public class MyClass
{
public DateTime Date { get; set; }
public List<LetterInfos> CourriersListe { get; set; }
}
LetterInfos 有日期、名称和标题。
Selection 是一个 LetterInfos 对象,我想在我的列表中单击它时获取它。
我正在使用 mvvm light,所以在我的 ViewModel 构造函数中我有这个:
SelectionCommand = new RelayCommand<LetterInfos>(OnSelectionElement);
我试图移动外部列表框中的交互段落,但我只能获取 MyClass 选定项,并且我想选择一个 LetterInfos 项.. 任何人都可以帮助我吗?谢谢!!
【问题讨论】:
标签: c# xaml windows-phone-8 listbox