windows 8 MSDN Examples 中一個奇怪的問題

來源:互聯網
上載者:User

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 }

每點擊一次按鈕,將刪除一個紅色的方塊。但當方塊刪除的只剩一個時,再點擊按鈕刪除時會報錯“Value does not fall within the expected range.”
很奇怪的提示,明明還有一個,怎麼就刪不掉呢?難道rectangleItems.Items不可為空嗎?實驗一下,調用rectangleItems.Items.Clear()方法刪除rectangleItems.Items中的所有項,反應正常;又試了下,在XAML中<ItemsControl.Items>中的方塊直接都刪除,任然可以運行。

不知有沒有人也遇到了類似的問題,這到底是什麼原因呢?

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.