コード例 #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Toy NewToy = new Toy();



            NewToy.Price = Convert.ToDouble(txtPrice.Text);

            if (string.IsNullOrEmpty(txtManufacturer.Text))
            {
                MessageBox.Show("Please enter a manufacturer");
            }
            else
            {
                NewToy.Manufacturer = txtManufacturer.Text;
            }

            if (string.IsNullOrEmpty(txtName.Text))
            {
                MessageBox.Show("Please enter a toy name");
            }
            else
            {
                NewToy.Name = txtName.Text;
            }



            if (double.TryParse(txtPrice.Text.ToString(), out double f))
            {
                NewToy.Price = Convert.ToDouble(txtPrice.Text);
            }
            else
            {
                MessageBox.Show("Please enter a valid price");
            }

            lbToys.Items.Add(NewToy);
        }
コード例 #2
0
        private void lbToys_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Toy selectedToy = (Toy)lbToys.SelectedItem;

            MessageBox.Show(selectedToy.GetAisle());
        }