IEditableCollectionView.CancelNew 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
结束添加事务并放弃挂起的新项。
public:
void CancelNew();
public void CancelNew ();
abstract member CancelNew : unit -> unit
Public Sub CancelNew ()
示例
以下示例显示一个窗体,该窗体提示用户添加新项。 如果用户提交表单,则示例调用 CommitNew 以将项添加到集合中。 如果用户取消窗体,则示例调用 CancelNew 以放弃该项。 有关整个示例,请参阅 使用 IEditableCollectionView 示例更改集合。
IEditableCollectionView editableCollectionView =
itemsControl.Items as IEditableCollectionView;
if (!editableCollectionView.CanAddNew)
{
MessageBox.Show("You cannot add items to the list.");
return;
}
// Create a window that prompts the user to enter a new
// item to sell.
ChangeItemWindow win = new ChangeItemWindow();
//Create a new item to be added to the collection.
win.DataContext = editableCollectionView.AddNew();
// 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();
}
Dim editableCollectionView As IEditableCollectionView = TryCast(itemsControl.Items, IEditableCollectionView)
If Not editableCollectionView.CanAddNew Then
MessageBox.Show("You cannot add items to the list.")
Return
End If
' Create a window that prompts the user to enter a new
' item to sell.
Dim win As New ChangeItemWindow()
'Create a new item to be added to the collection.
win.DataContext = editableCollectionView.AddNew()
' 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 CBool(win.ShowDialog()) Then
editableCollectionView.CommitNew()
Else
editableCollectionView.CancelNew()
End If