Binding ItemsControl
to an ObservableCollection<T>
places an extra {NewItemPlaceholder}
in the control at runtime. How can I remove it?
N.B. I have seen posts related to this problem but those are limited to DataGrid
where you can set CanUserAddRows
or IsReadOnly
properties to get rid of this item. ItemsControl
doesn't have any such property.
XAML
Here's my ItemsControl
(MyPoints
is ObservableCollection<T>
in the underlying ViewModel):
<ItemsControl ItemsSource="{Binding MyPoints}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="FrameworkElement">
<Setter Property="Canvas.Left" Value="{Binding Path=X}" />
<Setter Property="Canvas.Top" Value="{Binding Path=Y}" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type vm:PointVM}">
<Ellipse Width="10" Height="10" Fill="#88FF2222" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
This displays an extra point at 0,0. Live Property Explorer shows that this point is bound to the {NewItemPlaceholder}
object.