WPF DataBinding with MVVM and User Controls

前端 未结 2 1308
情深已故
情深已故 2020-12-06 03:45

Let\'s say I have a Customer Window showing information about a customer, like Name, address and phone number. On the bottom there is a DataGrid of their orders. Of course

2条回答
  •  青春惊慌失措
    2020-12-06 04:32

    There are many ways to skin a cat. The way I've been doing this is by having my CustomerViewModel have a property of type OrdersViewModel. Then in the constructor (or wherever you are setting the customer) have it set the "OrdersContext" with a new OrdersViewModel passing in the customer.orders.

    XAML:

    
    

    ViewModel:

    public CustomerViewModel(Customer customer)
    {
        Customer = customer;
        OrdersContext = new OrdersViewModel(customer.Orders);
    }
    

提交回复
热议问题