Learning the basic concepts of the MVVM pattern
Before starting to dig into the MVVM pattern, let's try to better understand the problem we're trying to solve. Let's assume we're building an e-commerce application that enables users to add products to a cart and submit an order. The application will have a summary page with a recap of the order and a button to submit the order. This is how the event handler connected to the Button
control might look like:
private void OnBtnOrderClick(object sender, Routed EventArgs e) { var itemsInBasket = _basketListBox.Items.Cast <IOrderItem>().ToArray(); if (itemsInBasket.Length <= 0) { return; } // Validate Shopping Basket if (itemsInBasket.Any(item => item.Quantity < 0 ...