本文整理匯總了C#中System.ComponentModel.IEditableCollectionViewAddNewItem.AddNewItem方法的典型用法代碼示例。如果您正苦於以下問題:C# IEditableCollectionViewAddNewItem.AddNewItem方法的具體用法?C# IEditableCollectionViewAddNewItem.AddNewItem怎麽用?C# IEditableCollectionViewAddNewItem.AddNewItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.ComponentModel.IEditableCollectionViewAddNewItem
的用法示例。
在下文中一共展示了IEditableCollectionViewAddNewItem.AddNewItem方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Window1
//引入命名空間
using System;
using System.ComponentModel;
using System.Windows;
namespace IEditableCollectionViewAddItemExample
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
IEditableCollectionViewAddNewItem viewToAddDisparateItems =
catalogList.Items as IEditableCollectionViewAddNewItem;
if (!viewToAddDisparateItems.CanAddNewItem)
{
MessageBox.Show("You cannot add items to the list.");
return;
}
// Create a window that prompts the user to enter a new
// item to sell.
AddItemWindow win = new AddItemWindow();
// Create an item, depending on which RadioButton is selected.
// Radio buttons correspond to book, cd, dvd, or other.
LibraryItem newItem;
if ((bool)book.IsChecked)
{
newItem = new Book("Enter the book title", "Enter an Author", "Enter a Genre",
"Enter a call number", DateTime.Now + new TimeSpan(21, 0, 0, 0));
}
else if ((bool)cd.IsChecked)
{
newItem = new MusicCD("Enter the Album", "Enter the artist", 0, "CD.******",
DateTime.Now + new TimeSpan(14, 0, 0, 0));
}
else if ((bool)dvd.IsChecked)
{
newItem = new MovieDVD("Enter the movie title", "Enter the director",
"Enter the genre", new TimeSpan(), "DVD.******",
DateTime.Now + new TimeSpan(7, 0, 0, 0));
}
else
{
newItem = new LibraryItem("Enter the title", "Enter the call number",
DateTime.Now + new TimeSpan(14, 0, 0, 0));
}
// Add the new item to the collection by calling
// IEditableCollectionViewAddNewItem.AddNewItem.
// Set the DataContext of the AddItemWindow to the
// returned item.
win.DataContext = viewToAddDisparateItems.AddNewItem(newItem);
// 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())
{
viewToAddDisparateItems.CommitNew();
}
else
{
viewToAddDisparateItems.CancelNew();
}
}
}
}