示例#1
0
        private void BtnEdtPrd_Click(object sender, RoutedEventArgs e)
        {
            // save index of item
            int mark = LvCategoue.SelectedIndex;
            // check if item is existed.
            if (mark != -1)
            { 
                // get product from selected item.
                Product p = LvCategoue.SelectedItem as Product;

                // realize a window
                AddProductWindow window = new AddProductWindow();                

                // add infomation for this window
                window.TxtName.Text = p.Name;               // name
                window.TxtPrice.Text = p.Price.ToString();  // price
                window.TxtInfo.Text = p.Info;               // info
                window.TxtUrlPic.Text = p.UrlOfPic;         // url of pic
                // disable add button, show save button
                window.BtnAdd.Visibility = Visibility.Hidden;
                window.BtnSave.Visibility = Visibility.Visible;
                window.item = p;

                // show dialog
                window.ShowDialog();
                
                // update item
                WebSite.ListOfProduct.RemoveAt(mark);
                WebSite.ListOfProduct.Insert(mark, window.item);
            }
        }
示例#2
0
 private void BtnAddPrd_Click(object sender, RoutedEventArgs e)
 {
     // Show window to user can add infomation about product
     AddProductWindow window = new AddProductWindow();
     window.ShowDialog();
     // Set selected item
     LvCategoue.SelectedIndex = WebSite.ListOfProduct.Count;
 }