我一直在弄清楚如何将下拉列表绑定到我的绑定列表框。我想显示一个列表,其中包含下拉列表中显示的所有乘客及其座位号。管理员应该能够通过下拉列表更改乘客的座位号。
我曾尝试查看嵌套绑定,但找不到任何提及我的问题的内容。
XAML
<Page
x:Class="FlightApplication.Passengers"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FlightApplication"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:fdata="using:FlightApplication.Models"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ListBox x:Name="ListBox1" Margin="5" Width="450" Height="200" HorizontalAlignment="Left" ItemsSource="{x:Bind PassengersList}" FontFamily="Segoe UI">
<ListBox.ItemTemplate>
<DataTemplate x:Name="PassengerLineTemplate" x:DataType="fdata:Passenger">
<StackPanel Orientation="Vertical" Margin="2">
<TextBlock>
<Run Text="{x:Bind LastName}"/>
<Run Text=" "/>
<Run Text="{x:Bind FirstName}"/>
</TextBlock>
<TextBlock>
<Run Text="{x:Bind Class}"/>
<Run Text=" - "/>
<Run Text="{x:Bind SeatNr}"/>
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Page>
namespace FlightApplication
{
public sealed partial class Passengers : Page
{
public ObservableCollection<Passenger> PassengersList = new ObservableCollection<Passenger>();
public Passengers()
{
this.InitializeComponent();
//ListBox1.DataContext = PassengersList; Do i use this?
}
}
}