zoukankan      html  css  js  c++  java
  • windows 8 MSDN Examples 中一个奇怪的问题

    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 items
    19          in the grid re-flow into position when one of the child items
    20          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>中的方块直接都删除,任然可以运行。

    不知有没有人也遇到了类似的问题,这到底是什么原因呢?

  • 相关阅读:
    3.默认参数的注意事项
    2.关键字global,nonlocal
    1.函数的结构,调用,传参,形参,实参,args,kwargs,名称空间,高阶函数
    19. 实现一个整数加法计算器(多个数相加):
    20.文件操作
    18.使用for循环计算+1-3+5-7+9-11+13...99的结果
    ubuntu docker更新镜像源
    虚拟环境的使用
    前端基础之HTML
    jQuery基本使用
  • 原文地址:https://www.cnblogs.com/chengyujia/p/2569709.html
Copyright © 2011-2022 走看看