コード例 #1
0
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            if (itemsControl.SelectedItem == null)
            {
                MessageBox.Show("Выделите запись.");
                return;
            }

            var editableCollectionView =
                itemsControl.Items as IEditableCollectionView;

            // Create a window that prompts the user to edit an item.
            editableCollectionView.EditItem(itemsControl.SelectedItem);
            var win = new ChangeItem {
                DataContext = itemsControl.SelectedItem
            };

            // If the user submits the new item, commit the changes.
            // If the user cancels the edits, discard the changes.
            if ((bool)win.ShowDialog())
            {
                editableCollectionView.CommitEdit();
            }
            else
            {
                editableCollectionView.CancelEdit();
            }
        }
コード例 #2
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            var editableCollectionView =
                itemsControl.Items as IEditableCollectionView;

            if (!editableCollectionView.CanAddNew)
            {
                MessageBox.Show("Вы не можете добавить запись в список.");
                return;
            }

            // Create a window that prompts the user to enter a new
            // item to sell.
            var win = new ChangeItem {
                DataContext = editableCollectionView.AddNew()
            };

            //Create a new item to be added to the collection.

            // If the user submits the new item, commit the new
            // object to the collection.  If the user cancels
            // adding the new item, discard the new item.
            if ((bool)win.ShowDialog())
            {
                editableCollectionView.CommitNew();
            }
            else
            {
                editableCollectionView.CancelNew();
            }
        }