这是模型:
public class Customer
{
string Name;
public ObservableCollection<Order> orders;
}
public class Order
{
int Id;
public ObservableCollection<RequestStorage> Requests;
}
public class RequestStorage
{
string Text;
public ObservableCollection<Response> Responses;
}
public class Response
{
string Text;
}
绑定到CustomersViewModel的CustomersView.xaml具有一个属性ObservableCollection<*Customer*> Customers;
客户视图模型
<!-- language: c# -->
public class CustomersViewModel
{
public CustomersViewModel()
{
//Load customers from database to Customers
}
public ObservableCollection<Customer> Customers { get; set; }
}
CustomersView.xaml
窗口DataContext
设置为CustomersViewModel
<DataGrid ItemsSource="{Binding Path=Customers}">
...
<DataGridTextColumn Header="Customer name" Binding="{Binding Path=Name}" />
...
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DataGrid ItemsSource="{Binding Path=Orders}">
...
<DataGridTextColumn Binding="{Path=Id}" />
<DataGridTemplateColumn>
<ItemsControl Binding="{Path=Requests}" />
</DataGridTemplateColumn>
<DataGridTemplateColumn>
<ItemsControl DataContext="{Binding Requests}" Binding="{Path=Responses}" />
</DataGridTemplateColumn>
</DataGrid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
问:当 Responses 集合发生变化(例如添加了新的 Response)时,如何通知CustomersViewModel以便CustomersView.xaml为指定的客户更新其 UI?