The IEditableCollectionViewAddNewItem interface enables application developers to specify what type of object to add to a collection. This interface extends IEditableCollectionView, so you can add, edit, and remove items in a collection. IEditableCollectionViewAddNewItem adds the AddNewItem method, which takes an object that is added to the collection. This method is useful when the collection and objects that you want to add have one or more of the following characteristics:

The following example enables a user to add various types of items to a collection. The user can enter a new item and submit the entry or cancel the transaction. The example gets an IEditableCollectionViewAddNewItem from the Items property of a ListBox and creates an object, whose type is determined by the user. Then the example calls the AddNewItem method to add the object to the collection.

<StackPanelMargin="10"Width="250"><StackPanel.Resources><!--Add an event handler to select all text when
a TextBox gets focus.--><StyleTargetType="TextBox"><EventSetterEvent="GotFocus"Handler="TextBoxFocus"/></Style><!--Create a Template for HeaderedContentControl so the header is
to the left of the content.--><StyleTargetType="HeaderedContentControl"><SetterProperty="Margin"Value="2"/><SetterProperty="Focusable"Value="False"/><SetterProperty="Template"><Setter.Value><ControlTemplateTargetType="HeaderedContentControl"><DockPanelLastChildFill="False"><ContentPresenterContentSource="Header"DockPanel.Dock="Left"Focusable="False"VerticalAlignment="Center"/><ContentPresenterContentSource="Content"Margin="5,0,0,0"DockPanel.Dock="Right"VerticalAlignment="Center"/></DockPanel></ControlTemplate></Setter.Value></Setter></Style><StyleTargetType="Button"><SetterProperty="Width"Value="100"/><SetterProperty="Margin"Value="10,15,15,15"/></Style><!--The DataTemplate that is used when the user
enters a new LibraryItem.--><DataTemplateDataType="{x:Type src:LibraryItem}"><StackPanel><HeaderedContentControlHeader="Title"><TextBoxWidth="150"Text="{Binding Path=Title, Mode=TwoWay}"/></HeaderedContentControl><HeaderedContentControlHeader="Due Date"><TextBoxWidth="150"Text="{Binding Path=DueDate, StringFormat=d, Mode=TwoWay}"></TextBox></HeaderedContentControl><HeaderedContentControlHeader="Call Number"><TextBoxWidth="150"Text="{Binding Path=CallNumber, Mode=TwoWay}"/></HeaderedContentControl></StackPanel></DataTemplate><!--The DataTemplate that is used when the user
enters a new Book.--><DataTemplateDataType="{x:Type src:Book}"><StackPanel><HeaderedContentControlHeader="Title"><TextBoxWidth="150"Text="{Binding Path=Title, Mode=TwoWay}"/></HeaderedContentControl><HeaderedContentControlHeader="Author"><TextBoxWidth="150"Text="{Binding Path=Author, Mode=TwoWay}"/></HeaderedContentControl><HeaderedContentControlHeader="Genre"><TextBoxWidth="150"Text="{Binding Path=Genre, Mode=TwoWay}"/></HeaderedContentControl><HeaderedContentControlHeader="Due Date"><TextBoxWidth="150"Text="{Binding Path=DueDate, StringFormat=d, Mode=TwoWay}"/></HeaderedContentControl><HeaderedContentControlHeader="Call Number"><TextBoxWidth="150"Text="{Binding Path=CallNumber, Mode=TwoWay}"/></HeaderedContentControl></StackPanel></DataTemplate><!--The DataTemplate that is used when the user
enters a new MusicCD.--><DataTemplateDataType="{x:Type src:MusicCD}"><StackPanel><HeaderedContentControlHeader="Title"><TextBoxWidth="150"Text="{Binding Path=Title, Mode=TwoWay}"/></HeaderedContentControl><HeaderedContentControlHeader="Artist"><TextBoxWidth="150"Text="{Binding Path=Artist, Mode=TwoWay}"/></HeaderedContentControl><HeaderedContentControlHeader="Tracks"><TextBoxWidth="150"Text="{Binding Path=NumberOfTracks, Mode=TwoWay}"/></HeaderedContentControl><HeaderedContentControlHeader="Due Date"><TextBoxWidth="150"Text="{Binding Path=DueDate, StringFormat=d, Mode=TwoWay}"/></HeaderedContentControl><HeaderedContentControlHeader="Call Number"><TextBoxWidth="150"Text="{Binding Path=CallNumber, Mode=TwoWay}"/></HeaderedContentControl></StackPanel></DataTemplate><!--The DataTemplate that is used when the user
enters a new MovieDVD.--><DataTemplateDataType="{x:Type src:MovieDVD}"><StackPanel><HeaderedContentControlHeader="Title"><TextBoxWidth="150"Text="{Binding Path=Title, Mode=TwoWay}"/></HeaderedContentControl><HeaderedContentControlHeader="Director"><TextBoxWidth="150"Text="{Binding Path=Director, Mode=TwoWay}"/></HeaderedContentControl><HeaderedContentControlHeader="Length"><TextBoxWidth="150"Text="{Binding Path=Length, Mode=TwoWay}"/></HeaderedContentControl><HeaderedContentControlHeader="Genre"><TextBoxWidth="150"Text="{Binding Path=Genre, Mode=TwoWay}"/></HeaderedContentControl><HeaderedContentControlHeader="Due Date"><TextBoxWidth="150"Text="{Binding Path=DueDate, StringFormat=d, Mode=TwoWay}"/></HeaderedContentControl><HeaderedContentControlHeader="Call Number"><TextBoxWidth="150"Text="{Binding Path=CallNumber, Mode=TwoWay}"/></HeaderedContentControl></StackPanel></DataTemplate></StackPanel.Resources><!--One of the DataTemplates that defined above
is used by this ContentControl when the window is created.--><ContentControlContent="{Binding}"/><StackPanelOrientation="Horizontal"><ButtonIsDefault="True"Click="Submit_Click">_Submit</Button><ButtonIsCancel="True">_Cancel</Button></StackPanel></StackPanel>