Esempio n. 1
0
        void Save()
        {
            foreach (var textBox in root.Children.OfType <TextBox>())
            {
                BindingExpression be = textBox.GetBindingExpression(TextBox.TextProperty);
                be?.UpdateSource();
            }
            DateField.GetBindingExpression(DatePicker.SelectedDateProperty).UpdateSource();
            AuthorField.GetBindingExpression(ComboBox.SelectedItemProperty).UpdateSource();
            PublisherField.GetBindingExpression(ComboBox.SelectedItemProperty).UpdateSource();

            var booksCollection = (Application.Current as App).LibraryData.Books;

            if (impactType == ImpactType.Save)
            {
                if (!booksCollection.Contains <Book>(impact))
                {
                    (Application.Current as App).LibraryData.Books.Add(impact);
                }
                else
                {
                    MessageBox.Show("A book with the ISBN has already been added", "Error",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            Close();
        }