zoukankan      html  css  js  c++  java
  • silverlight,动态数据集合中,移除动态集合自身的内容

    在xaml的页面上创建一个x:Name为_list1的ListBox,其中ListBox里面的每一项是ListBoxItem

    if (_list1.SelectedItem == null)//如果_list1的选中项为空的情况下进行返回
    {
      return;
    }
    else
    {
      var list = _list1.SelectedItems;//获取_list1的所有的选中项
      List<ListBoxItem> OutList = new List<ListBoxItem>();//创建一个新的集合用来存储所有的ListBox的ListBoxItem,然后操作这个集合,遍历这个集合中的每一项,如果符合条件的情况下,那么在_list1里面删除掉这一项
      foreach (ListBoxItem item in list)
        {
          OutList.Add(item);
        }

      foreach (ListBoxItem item in OutList)//避免自己移除自己的情况,因为涉及到动态集合的改变
        {
          if (item.Content.ToString() != "附件表单")
          _list1.Items.Remove(item);
        }
    }

    //总体相当于使用了一个中间容器

    如果不适用中间的这个集合的情况下,可能会因为动态的移除而导致集合在执行过程中变化而导致出现无法正常执行

  • 相关阅读:
    2015年个人记录
    Win10如何新建用户怎么添加新账户
    快速搭建一个本地的FTP服务器
    天气接口
    一张图搞定OAuth2.0
    PHP TS 和 NTS 版本选择
    如何在 Laravel 中使用 SMTP 发送邮件(适用于 163、QQ、Gmail 等)
    Npm vs Yarn 之备忘详单
    浅谈CSRF
    值得看的cookie详解
  • 原文地址:https://www.cnblogs.com/itboy-2009/p/4277920.html
Copyright © 2011-2022 走看看