Http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.media.animation.repositionthemetransition.aspx
1 <Button Content="Remove Rectangle" Click="RemoveButton_Click"/> 2 3 <ItemsControl Grid.Row="1" x:Name="rectangleItems"> 4 <ItemsControl.ItemContainerTransitions> 5 <TransitionCollection> 6 7 <!-- Without this, there would be no animation when items 8 are removed. --> 9 <RepositionThemeTransition/>10 </TransitionCollection>11 </ItemsControl.ItemContainerTransitions>12 <ItemsControl.ItemsPanel>13 <ItemsPanelTemplate>14 <WrapGrid Height="400"/>15 </ItemsPanelTemplate>16 </ItemsControl.ItemsPanel>17 18 <!-- All these rectangles are just to demonstrate how the items19 in the grid re-flow into position when one of the child items20 are removed. -->21 <ItemsControl.Items>22 <Rectangle Fill="Red" Width="100" Height="100" Margin="10"/>23 <Rectangle Fill="Red" Width="100" Height="100" Margin="10"/>24 <Rectangle Fill="Red" Width="100" Height="100" Margin="10"/>25 <Rectangle Fill="Red" Width="100" Height="100" Margin="10"/>26 <Rectangle Fill="Red" Width="100" Height="100" Margin="10"/>27 <Rectangle Fill="Red" Width="100" Height="100" Margin="10"/>28 <Rectangle Fill="Red" Width="100" Height="100" Margin="10"/>29 <Rectangle Fill="Red" Width="100" Height="100" Margin="10"/>30 <Rectangle Fill="Red" Width="100" Height="100" Margin="10"/>31 </ItemsControl.Items>32 </ItemsControl>
1 private void RemoveButton_Click(object sender, RoutedEventArgs e)2 {3 if (rectangleItems.Items.Count > 0)4 rectangleItems.Items.RemoveAt(0);5 }
Each time you click a button, a Red Square is deleted. However, when only one block is deleted, the error "Value does not fall within the expected range." is returned when you click the delete button ."
A strange reminder is that there is another one. Why can't it be deleted? Cannot rectangleItems. Items be blank? Call rectangleItems. items. clear () method to delete rectangleItems. all Items in the Items, the response is normal. After trying again, <ItemsControl. the blocks in Items> are directly deleted and can still be run.
I wonder if anyone has encountered a similar problem. Why?