如果先前已经提出这个问题,我很抱歉,但我还没有找到解决方案。
使用标准的Northwind DataService,我有一个显示CustomerID的Combobox,从中我有一个成功链接到Listview,它显示与该CustomerID相关联的订单。但是我有第二个Listview,我想在Orders Listview中显示与SelectedItem相关联的Order_Details,这个ListView保持空白,这是一个错误,因为它应该包含所选订单的详细信息。我需要在'Loaded'上发生这些人群。
突出表详情如下: 客户(CustomerID),订单(CustomerID,OrderID),Order_Details(OrderID)。
这是我的xaml代码:
<StackPanel>
<Label Content="Customer ID" />
<ComboBox Name="customerIDComboBox"
DisplayMemberPath="CustomerID"
ItemsSource="{Binding}"
IsSynchronizedWithCurrentItem="True"
SelectedIndex="0" />
<ListView Name="ordersListView"
ItemsSource="{Binding Path=Orders}"
DisplayMemberPath="OrderID"
IsSynchronizedWithCurrentItem="True"
SelectedItem="0" >
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=OrderID, Mode=OneWay}"
Header="Order ID" Width="75"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=OrderDate, Mode=TwoWay}"
Header="Order Date" Width="150"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Freight, Mode=TwoWay}"
Header="Freight Cost" Width="75"/>
</GridView>
</ListView.View>
</ListView>
<ListView Name="detailsListView"
ItemsSource="{Binding Path=Order_Details}"
DisplayMemberPath="OrderID"
IsSynchronizedWithCurrentItem="True"
SelectedItem="0" >
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=OrderID, Mode=OneWay}"
Header="Order ID" Width="75"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=ProductID, Mode=TwoWay}"
Header="Product ID" Width="75"/>
</GridView>
</ListView.View>
</ListView>
</StackPanel>
有一些按钮,但它们与我的问题无关。
这是我的代码隐藏:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
context = new NorthwindEntities(new Uri(svcUri));
var customerQuery = from cust in context.Customers.Expand("Orders/Order_Details")
select cust;
trackedCustomers = new DataServiceCollection<Customer>(customerQuery,
TrackingMode.AutoChangeTracking,
"Customers",
OnPropertyChanged,
OnCollectionChanged);
this.LayoutRoot.DataContext = trackedCustomers;
}
catch (DataServiceQueryException ex)
{
MessageBox.Show("The query could not be completed:\n" + ex.ToString());
}
catch (InvalidOperationException ex)
{
MessageBox.Show("The following error occurred:\n" + ex.ToString());
}
}
答案 0 :(得分:0)
回答我自己的问题我知道,但它关闭了它。
<ListView Name="detailsListView"
ItemsSource="{Binding Path=Order_Details}"
DisplayMemberPath="OrderID"
IsSynchronizedWithCurrentItem="True"
SelectedItem="0" >
应替换为:
<ListView Name="detailsListView"
ItemsSource="{Binding Path=Orders/Order_Details}"
DisplayMemberPath="OrderID"
IsSynchronizedWithCurrentItem="True"
SelectedItem="0" >
这导致组合框/列表框/列表框的正确填充。