using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace ObjectBinding { public partial class ViewProduct : Window { Product product = new Product { ProductID = 42, ProductName = "Bugatti", CategoryID = 2, UnitPrice = 950000, UnitsInStock = 5 }; // Window constructor, binds UI to Product object initially. public ViewProduct() { InitializeComponent(); OneProductGrid.DataContext = product; } // Display the current status of the product. private void StatusButton_Click(object sender, RoutedEventArgs e) { MessageBox.Show(product.ToString()); } // Decrement the units in stock. private void BuyButton_Click(object sender, RoutedEventArgs e) { if (product.UnitsInStock > 0) { product.UnitsInStock--; } } } }